我的老板已经下载了我必须在应用程序中使用的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