Hi There,
My app has two PopupMenu buttons to allow color picking - one for foreground one for back. So I created a reusable DataTemplate for the gallery like so:
<DataTemplate x:Key="ColourPopupContentTemplate">
<Border Width="200">
<ribbon:ColorPickerGallery InitialColumnCount="10" HorizontalAlignment="Center" CanFilter="True" IsPreviewEnabled="True">
<ribbon:ColorPickerGallery.CategorizedItemsSource>
<x:Array Type="{x:Type media:SolidColorBrush}">
<media:SolidColorBrush ribbon:PopupGallery.Category="Subtle Colors" ribbon:ColorPickerGallery.LayoutBehavior="Shaded" Color="#FFFFFF" ribbon:ScreenTipService.ScreenTipHeader="White" />
<media:SolidColorBrush ribbon:PopupGallery.Category="Subtle Colors" ribbon:ColorPickerGallery.LayoutBehavior="Shaded" Color="#000000" ribbon:ScreenTipService.ScreenTipHeader="Black" />
<media:SolidColorBrush ribbon:PopupGallery.Category="Subtle Colors" ribbon:ColorPickerGallery.LayoutBehavior="Shaded" Color="#EEECE1" ribbon:ScreenTipService.ScreenTipHeader="Tan" />
<media:SolidColorBrush ribbon:PopupGallery.Category="Subtle Colors" ribbon:ColorPickerGallery.LayoutBehavior="Shaded" Color="#1F497D" ribbon:ScreenTipService.ScreenTipHeader="Dark Blue" />
<media:SolidColorBrush ribbon:PopupGallery.Category="Subtle Colors" ribbon:ColorPickerGallery.LayoutBehavior="Shaded" Color="#4F81BD" ribbon:ScreenTipService.ScreenTipHeader="Blue" />
<media:SolidColorBrush ribbon:PopupGallery.Category="Subtle Colors" ribbon:ColorPickerGallery.LayoutBehavior="Shaded" Color="#C0504D" ribbon:ScreenTipService.ScreenTipHeader="Red" />
<media:SolidColorBrush ribbon:PopupGallery.Category="Subtle Colors" ribbon:ColorPickerGallery.LayoutBehavior="Shaded" Color="#9BBB59" ribbon:ScreenTipService.ScreenTipHeader="Olive Green" />
<media:SolidColorBrush ribbon:PopupGallery.Category="Subtle Colors" ribbon:ColorPickerGallery.LayoutBehavior="Shaded" Color="#8064A2" ribbon:ScreenTipService.ScreenTipHeader="Purple" />
<media:SolidColorBrush ribbon:PopupGallery.Category="Subtle Colors" ribbon:ColorPickerGallery.LayoutBehavior="Shaded" Color="#4BACC6" ribbon:ScreenTipService.ScreenTipHeader="Aqua" />
<media:SolidColorBrush ribbon:PopupGallery.Category="Subtle Colors" ribbon:ColorPickerGallery.LayoutBehavior="Shaded" Color="#F79646" ribbon:ScreenTipService.ScreenTipHeader="Orange" />
<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>
</Border>
</DataTemplate>
I then want to reuse this in each of my PopupMenu's, for example like this (the interesting bit, being the PopupContentTemplate
which allows me to pick up the DataTemplate above:
<shared:PopupButton Grid.Row="1" Grid.Column="2" Margin="10,10,0,0" Width="45" PopupContentTemplate="{StaticResource ColourPopupContentTemplate}"
HasDropShadow="True" themes:ThemeProperties.CornerRadius="3" Background="White">
<shared:PopupButton.Content>
<StackPanel Orientation="Horizontal">
<Rectangle Height="15" Width="15" Fill="{Binding FillColorArgb, Mode=TwoWay}" />
</StackPanel>
</shared:PopupButton.Content>
</shared:PopupButton>
This all works.
However - I now want to add a different event handler for each PopupButton as one interacts with the foreground and the other with the background.
I hoped I might be able to do something like this:
<shared:PopupButton.Style>
<Style TargetType="{x:Type ribbon:ColorPickerGallery}">
<EventSetter Event="ItemClick" Handler="FillColorChanged" />
<EventSetter Event="SelectedItem" Handler="{Binding FillColorArgb, Mode=TwoWay, Converter={StaticResource StringColorConverter}}" />
</Style>
</shared:PopupButton.Style>
However - Visual Studio / WPF doesn't like it - giving me the error "'ColorPickerGallery' TargetType does not match type of element 'PopupButton'"
Any idea how I could style the PopupContentTemplate
from this location? If I can fix that, the rest works.
Thanks
[Modified 2 years ago]