Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Toolkit Color Picker edit template now no available colors

I have looked for a solution to my problem on Google for hours, but there isnt much information to find.

I am using WPF Toolkit v2.2.1.

I have a Color Picker control in my WPF application, which needs to be custom styled. I am editing the control template of the Color Picker in App.xaml to apply to all color pickers.

As soon as I choose to use the template all available colors dissapear from the Color Picker. I have tried to assign new available colors from code with no success.

The Collection of colors are there, they are just not displayed it seems.

This is how the CP is defines in my mainwindow.xaml

<xctk:ColorPicker x:Name="cpRing" SelectedColorChanged="cpRing_Changed" HorizontalAlignment="Left" Margin="238,5,0,0" VerticalAlignment="Top" Height="20" Width="39" Foreground="Black"/>

The control template is too large to paste here unfortunately. But this should be easily reproduceable by adding a CP to a wpf window and rightclick it in designview and choose Edit Template. As soon as it is applied the colors will dissapear, without changing anything.

Does anybody know what to do to get the avaiable colors to display when editing the control template?

Best regards

like image 963
Nicki Avatar asked Jul 24 '14 00:07

Nicki


1 Answers

yep, it has something wrong with it's style. But if you observe it's style carefully you will find out the problem:

search key word StandardColors or AvailableColors in xaml, here is StandardColors's template:

<ListBox x:Name="PART_StandardColors"  Grid.Row="1">
        <ListBox.Style>
            <Style TargetType="{x:Type ListBox}">
            <Setter Property="Background" Value="Transparent"/>
            <Setter Property="BorderThickness" Value="0"/>
            <Setter Property="ItemsPanel">
            ....
        </ListBox.Style>
</ListBox>

you can see the listbox has not set itemsource, so you can add it by yourself:

<ListBox x:Name="PART_StandardColors" ItemsSource="{TemplateBinding StandardColors}"  Grid.Row="1">

edit listbox of AvailableColors :

 <ListBox x:Name="PART_AvailableColors" ItemsSource="{TemplateBinding AvailableColors}" Grid.Row="1">

now it works.

like image 169
Rang Avatar answered Nov 15 '22 08:11

Rang