通过Binding更改属性后的WPF fire事件处理程序

时间:2012-12-10 15:15:02

标签: wpf mvvm event-handling

我的WPF应用程序有一个窗口,其中包含加载数据的第三方控件。 Control具有在数据开始加载和结束时显示和隐藏进度条的方法。我使用MVVM将数据绑定到我的控件。我需要属性指示何时数据加载开始和结束,并且此属性必须在后面的代码中可访问。我在窗口中使用Visibility =“Hidden”添加了CheckBox控件并将其绑定到我的ViewModel中的属性标志,还在Checked事件上添加了EventHandler:

<CheckBox Name="chkIndicator" Visibility="Hidden" IsChecked="{Binding IsDataLoading}" Checked="chkIndicator_Checked" />

在代码隐藏视图事件处理程序中:

private void chkIndicator_Checked(object sender, RoutedEventArgs e)
{
    if(this.chkIndicator.IsChecked.Value)
        tableViewOrders.ShowIndicator();
    else 
        tableViewOrders.HideIndicator();
}

加载数据时在ViewModel中:

public bool IsDataLoading
{
    get { return _isDataLoading;}
    set {
        _isDataLoading = value;
        PropertyChanged("IsDataLoading");
    }
}
...
public void MethodLoadingData()
{
    /*1*/ IsDataLoading = true;

    //here method for loading data to collection binded to tableViewOrders

    /*2*/ IsDataLoading = false;
}

当方法MethodLoadingData执行时,行/ 1 /工作正常 - 事件处理程序chkIndicator_Checked已触发,但当/ 2 / run时 - 不会触发eventhandler。 我错了的任何想法?

1 个答案:

答案 0 :(得分:0)

您是否尝试将“IsChecked”属性的绑定模式更改为两种方式