gpt4 book ai didi

wpf - 如何使用 Blend 或 VS Designer 编辑 WPF PropertyGrid 的默认样式模板

转载 作者:行者123 更新时间:2023-12-02 00:54:02 25 4
gpt4 key购买 nike

我正在使用Extended WPF Toolkit Community Edition v2.6来 self 项目中的 NuGet,但我不知道是否应该做更多事情来允许我主题化或自定义控件模板。

要求 Designer/Blend 为 PropertyGrid 控件创建现有默认模板的副本后,UI 被破坏。模板看起来正确,但在设计时或运行时不再起作用。

enter image description here

选择将默认模板复制到新的样式后:

Image

是否有一种简单的方法来编辑此控件的内置样式?我实际上只是想覆盖 PropertyGrid 的编辑器/标签的前景色/背景色。

我在 XAML 中尝试过一些手动操作,但效果有限:

<Style TargetType="{x:Type xctk:DropDownButton}">
<Setter Property="Background" Value="Black"/>
<Setter Property="Foreground" Value="White"/>
</Style>
<Style TargetType="{x:Type xctk:CustomPropertyItem}">
<Setter Property="Background" Value="Black"/>
<Setter Property="Foreground" Value="White"/>
</Style>
<Style TargetType="{x:Type xctk:PropertyGridEditorCollectionControl}">
<Setter Property="Background" Value="Black"/>
<Setter Property="Foreground" Value="White"/>
</Style>

当尝试创建属性容器样式时,通过复制默认样式,我收到“复制样式失败”的消息。来自 VS Designer 或 Blend 中的错误。

enter image description here

结果如下:

Error from Copy Style

我已尝试手动包含 Xceed Toolkit 程序集中的 generic.xaml,但尚未解决问题。

我尝试了两种引用资源的方法:

<ResourceDictionary Source="/Xceed.Wpf.Toolkit;component/themes/generic.xaml" />

<ResourceDictionary Source="pack://application:,,,/Xceed.Wpf.Toolkit;component/Themes/generic.xaml">

这是当我尝试设置 PropertyContainerStyle 时设计器的堆栈跟踪:

stack trace

最佳答案

Blend 中的“编辑副本”选项并不总是准确的。使用复制的模板时,您无法在 PropertyGrid 中看到 PropertyItem,因为未复制 ItemsSource。

查看针对“PropertyGrid”的样式中的“PART_PropertyItemsControl”:没有 ItemsSource。将其设置为:ItemsSource="{绑定(bind)属性,RelativeSource={RelativeSource TemplatedParent}}"您将看到 PropertyItems。

关于wpf - 如何使用 Blend 或 VS Designer 编辑 WPF PropertyGrid 的默认样式模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36093271/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com