[英]How to route IsEnabledChanged (not routed event) to an EventHandler WPF
我只是試圖在 IsEnabled 變為 false 時將 xaml 中的 NumericUpDown 元素的值重置為 0,但檢查 IsEnabled 更改不是路由事件。 這是我目前擁有的,它不起作用,因為此事件不是路由事件
我的 XAML 代碼:
<CheckBox Name="AirportTemplate">Airport</CheckBox>
<NumericUpDown Name="AirportToGen"
Width="300"
Minimum="0"
IsEnabled="{Binding ElementName=AirportTemplate, Path=IsChecked}"
IsEnabledChanged="ResetValueAirport"/>
我在 C# 后面的代碼
private void ResetValueAirport(object sender, EventArgs e)
{
if (!AirportToGen.IsEnabled)
{
AirportToGen.Value = 0;
}
}
我猜你正在使用NumericUpDown
class 形式的擴展 WPF 工具包,在這種情況下IsEnabledChanged
事件需要一個帶有簽名的處理程序private void handler(object sender, DependencyPropertyChangedEventArgs e)
。 所以在你后面的代碼中使用這個:
private void ResetValueAirport(object sender, System.Windows.DependencyPropertyChangedEventArgs e)
{
if (!AirportToGen.IsEnabled)
{
AirportToGen.Value = 0;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.