Hello guys,
I'd like to make a customizable editor with a button like modal style, but what I want is to reset the value when clicked.
For example, Property1 = "A".
In the editor, I change the Property1 value to "B" and when I click on the reset button, it resets to "A".
I can do it with a simple textbox and button, but it's not easy to implement it with a property grid.
Can you help me please?
3 Answers, 1 is accepted
Hi Yefan,
Thank you for your interest in our RadPropertyGrid control.
The control does not provide out of the box such functionality. You can try to achieve this reset mechanism using custom code. For your convenience, I have prepared a sample project which demonstrates a possible solution. You can use it as a starting point to implement it in your application.
Regards,
Dinko
Progress Telerik
Our thoughts here at Progress are with those affected by the outbreak.
Well, I reformulate my problem. I want to reset one property at a time in the property grid, without specifying the property name in advance in the xaml. I managed to do it with field templates with one textbox for string values, one radnumericdownup for numeric values + one "Init" button.
TelerikPropertyGrid.xaml
<
UserControl
x:Class
=
"Setics.Sttar.Gui.Common.TelerikPropertyGrid"
xmlns:local
=
"clr-namespace:Setics.Sttar.Gui.Common"
mc:Ignorable
=
"d"
d:DesignHeight
=
"300"
d:DesignWidth
=
"300"
>
<
StackPanel
xmlns:telerik
=
"http://schemas.telerik.com/2008/xaml/presentation"
>
<
StackPanel.Resources
>
<
local:FieldTemplateSelector
x:Key
=
"DataTemplateSelector"
>
<
local:FieldTemplateSelector.StringDataTemplate
>
<
DataTemplate
>
<
Grid
>
<
Grid.ColumnDefinitions
>
<
ColumnDefinition
Width
=
"350"
/>
<
ColumnDefinition
Width
=
"50"
/>
</
Grid.ColumnDefinitions
>
<
TextBox
Padding
=
"4,2,0,0"
telerik:AutoBindBehavior.UpdateBindingOnElementLoaded
=
"Text"
Grid.Column
=
"0"
/>
<
telerik:RadButton
x:Name
=
"InitButton"
Content
=
"Init"
Grid.Column
=
"1"
Click
=
"InitButton_Click"
/>
</
Grid
>
</
DataTemplate
>
</
local:FieldTemplateSelector.StringDataTemplate
>
<
local:FieldTemplateSelector.NumericDataTemplate
>
<
DataTemplate
>
<
Grid
>
<
Grid.ColumnDefinitions
>
<
ColumnDefinition
Width
=
"350"
/>
<
ColumnDefinition
Width
=
"50"
/>
</
Grid.ColumnDefinitions
>
<
telerik:RadNumericUpDown
x:Name
=
"NumericDataEditor"
Grid.Column
=
"0"
Minimum
=
"0"
Padding
=
"4,2,0,0"
telerik:AutoBindBehavior.UpdateBindingOnElementLoaded
=
"Value"
HorizontalContentAlignment
=
"Left"
HideTrailingZeros
=
"True"
/>
<
telerik:RadButton
x:Name
=
"InitButton"
Content
=
"Init"
Grid.Column
=
"1"
Click
=
"InitButton_Click"
/>
</
Grid
>
</
DataTemplate
>
</
local:FieldTemplateSelector.NumericDataTemplate
>
<
local:FieldTemplateSelector.CurrencyDataTemplate
>
<
DataTemplate
>
<
Grid
>
<
Grid.ColumnDefinitions
>
<
ColumnDefinition
Width
=
"350"
/>
<
ColumnDefinition
Width
=
"50"
/>
</
Grid.ColumnDefinitions
>
<
telerik:RadNumericUpDown
Grid.Column
=
"0"
Minimum
=
"0"
Padding
=
"4,2,0,0"
telerik:AutoBindBehavior.UpdateBindingOnElementLoaded
=
"Value"
HorizontalContentAlignment
=
"Left"
NumberDecimalDigits
=
"2"
CustomUnit
=
"€"
>
</
telerik:RadNumericUpDown
>
<
telerik:RadButton
x:Name
=
"InitButton"
Content
=
"Init"
Grid.Column
=
"1"
Click
=
"InitButton_Click"
/>
</
Grid
>
</
DataTemplate
>
</
local:FieldTemplateSelector.CurrencyDataTemplate
>
<
local:FieldTemplateSelector.DistanceDataTemplate
>
<
DataTemplate
>
<
Grid
>
<
Grid.ColumnDefinitions
>
<
ColumnDefinition
Width
=
"350"
/>
<
ColumnDefinition
Width
=
"50"
/>
</
Grid.ColumnDefinitions
>
<
telerik:RadNumericUpDown
Grid.Column
=
"0"
Minimum
=
"0"
Padding
=
"4,2,0,0"
telerik:AutoBindBehavior.UpdateBindingOnElementLoaded
=
"Value"
HorizontalContentAlignment
=
"Left"
NumberDecimalDigits
=
"3"
CustomUnit
=
"m"
/>
<
telerik:RadButton
x:Name
=
"InitButton"
Content
=
"Init"
Grid.Column
=
"1"
Click
=
"InitButton_Click"
/>
</
Grid
>
</
DataTemplate
>
</
local:FieldTemplateSelector.DistanceDataTemplate
>
<
local:FieldTemplateSelector.ReadOnlyDataTemplate
>
<
DataTemplate
>
<
TextBox
Padding
=
"4,2,0,0"
HorizontalContentAlignment
=
"Left"
telerik:AutoBindBehavior.UpdateBindingOnElementLoaded
=
"Text"
IsReadOnly
=
"True"
IsEnabled
=
"False"
/>
</
DataTemplate
>
</
local:FieldTemplateSelector.ReadOnlyDataTemplate
>
</
local:FieldTemplateSelector
>
</
StackPanel.Resources
>
<
telerik:RadPropertyGrid
x:Name
=
"PropertyGrid"
EditorTemplateSelector
=
"{StaticResource DataTemplateSelector}"
Item
=
"{Binding Employee}"
/>
<
Button
Height
=
"30"
Name
=
"RefreshDataButton"
Content
=
"Refresh Data"
Click
=
"RefreshDataButton_Click"
></
Button
>
</
StackPanel
>
</
UserControl
>
For example, I edit first name and last name, and now I want to reset the first name property value by clicking on the button without resetting the whole property item. How can I do it?
Hi Yefan,
Thank you for the provided code snippet.
What you can try to achieve your scenario is to store the value of each property on load in a Dictionary. Then inside the Init button click event, you can get the current PropertyGridField container, which its DataContext holds the PropertyDefinition. What's left is just to get the initial value from the dictionary.
To better demonstrate this, I have modified the sample project and attached it again. I hope this approach will work in your application.
Regards,
Dinko
Progress Telerik
Our thoughts here at Progress are with those affected by the outbreak.