【问题标题】:Select Editor in Extended WPF Toolkit PropertyGrid在扩展 WPF 工具包 PropertyGrid 中选择编辑器
【发布时间】:2023-03-18 22:31:01
【问题描述】:

使用扩展 WPF 工具包中的 PropertyGrid。我想为字段选择内置编辑器。

我知道我可以从模型中得到它,这样:

[Editor(typeof(TextBoxEditor), typeof(TextBoxEditor))]
public string LastName { get; set; }

但我想从 XAML 中获取它,类似这样(当然它是无效的):

<xctk:PropertyGrid.PropertyDefinitions>
    <xctk:PropertyDefinition TargetProperties="PetNames" Editor="TextBoxEditor" />
</xctk:PropertyGrid.PropertyDefinitions>

有没有办法在非默认编辑器中显示属性,而无需更改我的模型?

谢谢

【问题讨论】:

  • 我不确定我是否理解您的问题,但我认为专门设置控件的模型可以解决您的问题(您保留整个视图的模型,只需更改受影响的模型控制)。
  • 我的意思是一种从 XAML 中指定编辑器的方法,因此我不必在 C# 中使用属性指定它。谢谢

标签: wpf xaml toolkit xceed


【解决方案1】:

如前所述,在documentation 中,您可以通过设置EditingTemplate 使用DataTemplates 创建自定义编辑器,如下所示:

<xctk:PropertyGrid.EditorDefinitions>
    <xctk:EditorTemplateDefinition TargetProperties="PetNames">
        <xctk:EditorTemplateDefinition.EditingTemplate>
            <DataTemplate>
                <!-- put whatever control you would like here (including your own custom one) -->
                <TextBox Text="{Binding Value}" />
            </DataTemplate>
        </xctk:EditorTemplateDefinition.EditingTemplate>
    </xctk:EditorTemplateDefinition>
</xctk:PropertyGrid.EditorDefinitions>

【讨论】:

  • 是的,这是正确的方法,尽管您的代码是错误的。您不能将 EditorTemplateDefinition 放在 PropertyDefinition 内(它必须在外面,在 EditorDefinitions 标签中)。 PropertyGrid 中必须有两个不同的块:EditorDefinitions 和 PropertyDefinitions。如果您修复它,我会将您的答案标记为已接受。谢谢
  • 好收获。我不确定为什么我在那里有其他代码。无论如何,我已经更新了它。
猜你喜欢
  • 2015-05-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-03-08
相关资源
最近更新 更多