
I’m trying to bind the SelectedItem of a ColorPickerGallery to a binding within a DataGrid. I have a List of objects the DataGrid ItemSource is bound to, this works as expected with a number of different bindings. The ColorPickerGallery is an entry to a ContextMenu, essentially it is copied from your "Gallery Color Pickers Sample" though I am not using the Command hence binding to SelectedItem instead.
The binding gets from my “TraceColour” binding (I can see this debugging) it doesn’t set the appropriate Color though this doesn’t bother me. Selecting doesn’t raise the setter at all for the binding, I have tried all different Modes and update triggers. The ItemClick and SelectedItemChanged gets raised but I am unable to access the TraceColour property from within. There is a setter for TraceColour with an appropriate OnPropertyChanged setup, this binding works in other areas of my application.
Possibly my incorrect use of DataGrid but there appears to be no similar example to compare with. Any help on my issue would be appreciated.
Thanks
<DataGrid ItemsSource="{Binding OpTraceItems}" HeadersVisibility="Column" CanUserAddRows="False" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTemplateColumn Header="Line" >
<DataGridTemplateColumn.CellTemplate>
<DataTemplate >
<Line X2="50" StrokeThickness="4" VerticalAlignment="Center" Margin="10">
<Line.Stroke>
<SolidColorBrush Color="{Binding TraceColour}"/>
</Line.Stroke>
<Line.ContextMenu>
<ContextMenu >
<ribbon:ColorPickerGallery InitialColumnCount="10" HorizontalAlignment="Center" Width="245"
SelectedItem="{Binding TraceColour, Mode=TwoWay, Converter={StaticResource Brush2Color}}"
ItemClick="ColorPickerGallery_ItemClick" SelectedItemChanged="ColorPickerGallery_SelectedItemChanged">
<ribbon:ColorPickerGallery.ItemTemplate>
<DataTemplate>
<Rectangle Fill="{Binding BindsDirectlyToSource=True}" Width="20" Height="20" />
</DataTemplate>
</ribbon:ColorPickerGallery.ItemTemplate>
<ribbon:ColorPickerGallery.CategorizedItemsSource>
<x:Array Type="{x:Type media:SolidColorBrush}">
<media:SolidColorBrush ribbon:PopupGallery.Category="Standard Colors" ribbon:ColorPickerGallery.LayoutBehavior="Shaded" Color="#C00000" ribbon:ScreenTipService.ScreenTipHeader="Dark Red" />
<media:SolidColorBrush ribbon:PopupGallery.Category="Standard Colors" ribbon:ColorPickerGallery.LayoutBehavior="Shaded" Color="#FF0000" ribbon:ScreenTipService.ScreenTipHeader="Red" />
<media:SolidColorBrush ribbon:PopupGallery.Category="Standard Colors" ribbon:ColorPickerGallery.LayoutBehavior="Shaded" Color="#FFC000" ribbon:ScreenTipService.ScreenTipHeader="Orange" />
<media:SolidColorBrush ribbon:PopupGallery.Category="Standard Colors" ribbon:ColorPickerGallery.LayoutBehavior="Shaded" Color="#FFFF00" ribbon:ScreenTipService.ScreenTipHeader="Yellow" />
<media:SolidColorBrush ribbon:PopupGallery.Category="Standard Colors" ribbon:ColorPickerGallery.LayoutBehavior="Shaded" Color="#92D050" ribbon:ScreenTipService.ScreenTipHeader="Light Green" />
<media:SolidColorBrush ribbon:PopupGallery.Category="Standard Colors" ribbon:ColorPickerGallery.LayoutBehavior="Shaded" Color="#00B050" ribbon:ScreenTipService.ScreenTipHeader="Green" />
<media:SolidColorBrush ribbon:PopupGallery.Category="Standard Colors" ribbon:ColorPickerGallery.LayoutBehavior="Shaded" Color="#00B0F0" ribbon:ScreenTipService.ScreenTipHeader="Light Blue" />
<media:SolidColorBrush ribbon:PopupGallery.Category="Standard Colors" ribbon:ColorPickerGallery.LayoutBehavior="Shaded" Color="#0070C0" ribbon:ScreenTipService.ScreenTipHeader="Blue" />
<media:SolidColorBrush ribbon:PopupGallery.Category="Standard Colors" ribbon:ColorPickerGallery.LayoutBehavior="Shaded" Color="#002060" ribbon:ScreenTipService.ScreenTipHeader="Dark Blue" />
<media:SolidColorBrush ribbon:PopupGallery.Category="Standard Colors" ribbon:ColorPickerGallery.LayoutBehavior="Shaded" Color="#7030A0" ribbon:ScreenTipService.ScreenTipHeader="Purple" />
</x:Array>
</ribbon:ColorPickerGallery.CategorizedItemsSource>
</ribbon:ColorPickerGallery>
</ContextMenu>
</Line.ContextMenu>
</Line>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>