2013-09-10 44 views
-1

我有一個實現Inotifypropertychanged的類。我也有這個屬性,我註釋了通知。綁定可以工作到不實施Inotifypropertychanged的源屬性嗎?

private Color _CoolColor =Colors.Purple; 
    public Color CoolColor 
    { 
     get 
     { 
     return _CoolColor; 
     } 
     set 
     { 
     if (value != _CoolColor) 
     { 
      _CoolColor = (Color)value; 
      //OnPropertyChanged("CoolColor"); 
     } 
     } 
    } 

一個在我的XAML綁定重視這個屬性:

BusTextColor="{Binding Path=CoolColor}" 

/// <summary> 
    /// Color used for the text containing the hex value of the bus 
    /// </summary> 
    public Color BusTextColor 
    { 
     get 
     { 
     return (Color)GetValue(BusTextColorProperty); 
     } 
     set 
     { 
     SetValue(BusTextColorProperty, value); 
     } 
    } 
    public static readonly DependencyProperty BusTextColorProperty = 
     DependencyProperty.Register("BusTextColor", 
     typeof(Color), typeof(SignalGraph), 
     new FrameworkPropertyMetadata(new Color(), new PropertyChangedCallback(CreateBrushesAndReDraw))); 

我只綁定這個原因,我想確保我是不是瘋了,但因爲我的BusTextColor是我一定是瘋了CoolColor更改時更新。有人請讓它停止工作。

我只是這樣做,因爲另一個依賴屬性我有沒有正確綁定到我的視圖模型。我知道這可能有一些明顯的原因,但我肯定錯過了它。

編輯: 這篇文章很有意思。但在我的情況下,我實現了Inotifypropertychanged接口,我只是不引發事件OnPropertyChanged。我意識到我也應該發佈。

protected void OnPropertyChanged(string name) 
{ 
    PropertyChangedEventHandler handler = PropertyChanged; 
    if (handler != null) 
    { 
    handler(this, new PropertyChangedEventArgs(name)); 
    } 
} 
+0

未採取'INotifyPropertyChanged',而不是引發事件的結合的結合,而不是假設我使用的語法不正確的代碼干涉檢查2個不同的東西。你在說哪一個? –

+0

這可能是相關的,不知道它是否適用,因爲你說你實際上有類中的接口:http://stackoverflow.com/questions/7767218/why-does-the-binding-update-without-implementing -inotifypropertychanged –

+0

啊我的意思是不提高事件。這個事件是不是必須爲了財產變化而傳播? –

回答

0

既然沒有人有一個明顯的答案,我知道我做錯了什麼別的地方,什麼我張貼應該工作。

最終意識到這是一個錯誤,我以前還。某處我手動更改了目標的值並打破了綁定。需要開始用於在這些情況下在XAML

1

有人請使其停止工作。

只需設置BindingModeOneTime

相關問題