-2

In RadGrid there is a good way to customize content in cells with c#, with GridViewColumnBase. Is it also possible to customize RadPropertyGrid throgh code? I want to add a button to a RadPropertyGrid through code - not through xaml. I have the radProperty in xaml: <telerik:RadPropertyGrid x:Name="radProperty" />

On initialization of xaml, I have this code:

    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);
    }

I actually have to add a combobox instead of a button, but I think if I can add a simple button, then I have the technique for adding a var comboBox = new Telerik.Windows.Controls.RadComboBox();

Kenneth Bo Christensen
  • 2,256
  • 2
  • 18
  • 21

1 Answers1

1

The EditorTemplate property is supposed to be set to a DataTemplate that you may define as a resource in your 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;
mm8
  • 163,881
  • 10
  • 57
  • 88
  • Thank you very much! Unfortunately it has to be done in code - not xaml because it's a dynamic content. – Kenneth Bo Christensen Mar 06 '20 at 13:48
  • So create the template programmatically then: https://stackoverflow.com/questions/44751373/combining-datatemplates-at-runtime/44757321#44757321 – mm8 Mar 06 '20 at 14:14