I want to use the color picker in my wpf application, and I saw a beautiful page on this codeproject page . The control works fine until I want to connect the control to the viewmodel. I created a small test program with this view model:
public class ColorViewModel : ViewModelBase
{
public ColorViewModel()
{
LineColor = Brushes.Yellow;
}
SolidColorBrush _brushColor;
public SolidColorBrush LineColor
{
get { return _brushColor; }
set
{
_brushColor = value;
RaisePropertyChanged(() => LineColor);
}
}
}
The test program has a text box and colorpicker controls:
<StackPanel Orientation="Horizontal">
<TextBlock Text="Please Select a Color" FontWeight="Bold" Margin="10"
Foreground="{Binding Path=LineColor, UpdateSourceTrigger=PropertyChanged}"/>
<vw:ColorPickerControlView x:Name="ForeColorPicker" Margin="10"
CurrentColor="{Binding Path=LineColor, UpdateSourceTrigger=PropertyChanged }"/>
</StackPanel>
In the loaded event of the main window of my test application, I set the viewmodel to the datacontext as follows:
DataContext = new ColorViewModel();
, LineColor viewmodel CurrentColor ColorPickerControlView. CurrentControl ColorPickerControlView . :
public ColorPickerControlView()
{
this.DataContext = this;
InitializeComponent();
CommandBindings.Add(new CommandBinding(SelectColorCommand, SelectColorCommandExecute));
}
UserControl this.DataContext = this; , . , CurrentColor? ? ?