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

标签 wpf propertygrid expression-blend-4 wpf-extended-toolkit

我正在使用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/

相关文章:

c# - LINQ 选择动态列和值

wpf - 如何解决 Blend 4 中嵌入式用户控件中的设计时静态资源

c# - 可以在代码中使用 Blend SDK 类,但不能使用 XAML (Prism Desktop)

c# - 如何使用 livecharts 动态创建笛卡尔图表

WPF 图像控件裁剪

c# - 将 D3DImage 转换为字节数组

c# - VS 设计时错误 - 类型 'ICustomType[]' 的对象无法转换为类型 'ICustomType[]'

C# 运行时类创建

c# - .NET 属性网格 - 使用 App.config 设置可浏览(bool)