簡體   English   中英

如何將 IsEnabledChanged(未路由事件)路由到 EventHandler WPF

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM