Добавьте кнопку в Telerik WPF RadPropertyGrid через код - PullRequest
0 голосов
/ 06 марта 2020

В RadGrid есть хороший способ настроить содержимое в ячейках с c# с помощью GridViewColumnBase. Можно ли также настроить код проверки RadPropertyGrid? Я хочу добавить кнопку в RadPropertyGrid через код, а не через xaml. У меня есть radProperty в xaml: <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();

1 Ответ

1 голос
/ 06 марта 2020

Предполагается, что для свойства EditorTemplate установлено значение DataTemplate, которое вы можете определить в качестве ресурса в своем XAML:

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