应用程序:应用程序,INotifyPropertyChanged不会引发NotifyPropertyChanged

时间:2011-09-15 19:19:19

标签: c# silverlight windows-phone-7 inotifypropertychanged

class App : Application,INotifyPropertyChanged未提出NotifyPropertyChanged

我想要来自其他类的更新填充属性(样式中的App.xaml中的路径)。我想从其他类中执行此操作。就像这样:App.xaml.cs

public bool isShuffle {
    get {
      return _isShufle;
    }
    set {
        _isShufle = value;
        OnPropertyChanged(new PropertyChangedEventArgs("isShuffle"));
    }
}

的App.xaml:

<Path Height="59"
      Data="M15.999,4.3080001 C17.228001,4.309 18.402,4.5219998 19.514,4.8779998 L18.6"
      Fill="{Binding isShuffle ,
                     Converter={StaticResource AudioColor}}"
      />

但没有更新。

1 个答案:

答案 0 :(得分:2)

public bool isShuffle {
      get {
        return _isShufle;
      }
      set {
        if (_isShufle != value){
         _isShufle = value;
        OnPropertyChanged("isShuffle");

}           }         }

// Create the RaisePropertyChanged method to raise the event
    protected void OnPropertyChanged(string name)
    {
        PropertyChangedEventHandler handler = PropertyChanged;
        if (handler != null)
        {
            handler(this, new PropertyChangedEventArgs(name));
        }
    }

    public event PropertyChangedEventHandler PropertyChanged;

此外,您需要确保为绑定设置上下文。例如,如果您尚未设置DataContext,则可以使用ElementName

`<Application 
    x:Class="MyApp.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/p...
    x:Name="control" ...`

你的绑定本身

<Path Height="59"
                            Data="M15.999,4.3080001 C17.228001,4.309 18.402,4.5219998 19.514,4.8779998 L18.6"
                            Fill="{Binding Path=IsShuffle, ElementName=control, Converter={StaticResource AudioColor}}"
                            />