【问题标题】:WPF Toolkit Color Picker edit template now no available colorsWPF 工具包颜色选择器编辑模板现在没有可用的颜色
【发布时间】:2014-09-15 09:04:00
【问题描述】:

我已经在 Google 上寻找解决问题的方法几个小时,但找不到太多信息。

我正在使用 WPF Toolkit v2.2.1。

我的 WPF 应用程序中有一个颜色选择器控件,需要自定义样式。我正在 App.xaml 中编辑 Color Picker 的控件模板以应用于所有颜色选择器。

一旦我选择使用模板,所有可用的颜色都会从拾色器中消失。我试图从代码中分配新的可用颜色,但没有成功。

颜色集合在那里,它们似乎没有显示。

这是在我的 mainwindow.xaml 中定义 CP 的方式

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

很遗憾,控件模板太大,无法在此处粘贴。但这应该很容易通过将 CP 添加到 wpf 窗口并在设计视图中右键单击它并选择编辑模板来重现。一旦应用,颜色就会消失,不会改变任何东西。

有人知道如何在编辑控件模板时显示可用的颜色吗?

最好的问候

【问题讨论】:

    标签: wpf xaml colors toolkit picker


    【解决方案1】:

    是的,它的风格有问题。但是如果你仔细观察它的风格你会发现问题:

    在xaml中搜索关键字StandardColorsAvailableColors,这里是StandardColors的模板:

    <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>
    

    可以看到listbox没有设置itemsource,可以自行添加:

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

    编辑AvailableColors的列表框:

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

    现在可以了。

    【讨论】:

    • 它有效!杰出的。非常感谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-27
    相关资源
    最近更新 更多