我的老闆已經下載了我必須在應用程序中使用的xaml控件。它看起來像確定,但有一個與內在邏輯奇怪的麻煩 - 該 財產CurrentColor
(我需要在我們的應用程序使用)中control.xaml.cs
文件等被定義爲:將控件綁定到另一個屬性
public SolidColorBrush CurrentColor
{
get { return (SolidColorBrush)GetValue(CurrentColorProperty); }
set
{
SetValue(CurrentColorProperty, value);
ActiveColor = CurrentColor;
}
}
我用我的對話框這個控制(有它自己的視圖模型類)和 我寫這樣的結合:在myOwnViewModel.cs
CurrentColor="{Binding myOwnViewModel.ColorActualValue, Mode=Default, UpdateSourceTrigger=PropertyChanged}">
(實現INotifyPropertyChanged
)我有我的財產
public SolidColorBrush ColorActualValue{ // here is some logic}
但是當我調試應用程序,我從來沒有定位我CurrentColor - 我經常去CurrentColor
從control.xaml.cs
我怎麼能結合從我ViewModel
這個「第三者」控制我的財產?
也許這是因爲(control.xaml.cs):
public static DependencyProperty CurrentColorProperty =
DependencyProperty.Register("CurrentColor", typeof(SolidColorBrush), typeof(ColorPickerComboBox), new PropertyMetadata(Brushes.Chocolate));
public static RoutedEvent ActiveColorChangedEvent = EventManager.RegisterRoutedEvent("ActiveColorChanged",
RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(ColorPickerComboBox));
我已經找到了問題What's wrong with "DataContext = this" in WPF user controls?並從該控件的構造函數刪除DataContext = this;
- 但是這仍然沒有幫助
設置的DataContext到烏爾視圖模型,然後從烏爾約束力的聲明 –
你刪除視圖模型視圖模型類綁定到屬性myOwnViewModel.ColorActualValue,但在您的ViewModel中它命名爲CurrentColor。檢查輸出窗口是否有綁定錯誤。 – GreenEyedAndy
GreenEyedAndy - 對於此錯誤感到抱歉,我已更正問題 – curiousity