The WPF Toolkit Color Picker editing template is now unavailable.

I searched for a solution to my problem on Google for several hours, but no information was found.

I am using WPF Toolkit v2.2.1.

I have a color control in my WPF application that should be styled in the usual style. I am editing the Color Picker management template in App.xaml to apply to all color selections.

As soon as I decided to use the template, all available colors disappear from the Color Picker. I tried to assign new available colors from code without success.

There is a collection of flowers; they simply are not displayed.

This is how CP is defined 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 management template is too large to insert here, unfortunately. But this should be easily reproduced by adding CP to the wpf window and right-click on it in the design and select "Edit Template". Once it is applied, the colors will disappear without changing anything.

Does anyone know what to do to display the available colors when editing a control template?

Best wishes

+6
source share
1 answer

yep, he has something wrong with this style. But if you carefully study this style, you will find a problem:

find the keyword StandardColors or AvailableColors in xaml, here is the StandardColors 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 that the list did not set itemsource, so you can add it yourself:

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

change list from AvailableColors :

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

now it works.

+5
source

Source: https://habr.com/ru/post/972740/


All Articles