【问题标题】:Add button to Telerik WPF RadPropertyGrid through code通过代码将按钮添加到 Telerik WPF RadPropertyGrid
【发布时间】:2020-03-06 06:38:43
【问题描述】:

在 RadGrid 中,有一个很好的方法可以使用 c# 和 GridViewColumnBase 自定义单元格中的内容。是否也可以通过代码自定义 RadPropertyGrid? 我想通过代码向 RadPropertyGrid 添加一个按钮 - 而不是通过 xaml。 我在 xaml 中有 radProperty:<telerik:RadPropertyGrid x:Name="radProperty" />

在初始化 xaml 时,我有以下代码:

    public Properties()
    {
        InitializeComponent();

        var button = new Button() { Height = 20, Width = 100, Content = "Test" };

        var property = new Telerik.Windows.Controls.Data.PropertyGrid.PropertyDefinition()
        {
            DisplayName = "Content",
            EditorTemplate.Template = button (so much incorrect but how ?)
        };

        this.radProperty.PropertyDefinitions.Add(property);
    }

我实际上必须添加一个组合框而不是一个按钮,但我认为如果我可以添加一个简单的按钮,那么我就有添加var comboBox = new Telerik.Windows.Controls.RadComboBox();的技术

【问题讨论】:

    标签: c# wpf dynamic telerik


    【解决方案1】:

    EditorTemplate 属性应该设置为您可以在 XAML 中定义为资源的 DataTemplate

    <Window.Resources>
        <DataTemplate x:Key="template">
            <Button Content="Button" />
        </DataTemplate>
    </Window.Resources>
    

    var property = new Telerik.Windows.Controls.Data.PropertyGrid.PropertyDefinition()
    {
        DisplayName = "Content",
    };
    property.EditorTemplate = this.Resources["template"] as DataTemplate;
    

    【讨论】:

    猜你喜欢
    • 2014-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多