2

I'm trying to assign different increment values to different fields of an object. For example, consider a class has who has int1 and int2, and when I set ShowAdvancedOptions to true for my PropertyGrid, integer up down buttons are put in the textbox with no problems. But I want to be able to edit how much the numbers are incremented individually. Is there a way I can ahcieve this?
Edit:
Here is the code:

public MainWindow()    
        {   
            InitializeComponent();

            Sample or = new Sample();
            pg.SelectedObject = or;
            pg.ShowAdvancedOptions = true;
        }

MainWindow.xaml:

<Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApp1"
        xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit" xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid" x:Class="WpfApp1.MainWindow"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <xctk:PropertyGrid x:Name="pg"  HorizontalAlignment="Left" Margin="328,70,0,0" VerticalAlignment="Top" Height="275" Width="341"/>


</Window>

and the Sample class:

public class Sample
    {
        public enum SampleEnum
        {
            A,B,C,D,E
        }
        #region private fields
        private SampleEnum _SampleEnum;
        private int _Value;
        #endregion

        #region Public Properties

        [Category("Sample")]
        [DisplayName("Sample Value")]
        [DefaultValue(3)]
        public int Value { set; get; }

       #endregion

    }
hebele
  • 75
  • 9

1 Answers1

2

You could define a custom EditorTemplate per property:

<xctk:PropertyGrid x:Name="pg">
    <xctk:PropertyGrid.EditorDefinitions>
        <xctk:EditorDefinition>
            <xctk:EditorDefinition.PropertiesDefinitions>
                <xctk:PropertyDefinition Name="int1" />
            </xctk:EditorDefinition.PropertiesDefinitions>
            <xctk:EditorDefinition.EditorTemplate>
                <DataTemplate>
                    <xctk:PropertyGridEditorIntegerUpDown Increment="10" Value="{Binding Value}" />
                </DataTemplate>
            </xctk:EditorDefinition.EditorTemplate>
        </xctk:EditorDefinition>
    </xctk:PropertyGrid.EditorDefinitions>

</xctk:PropertyGrid>

In the above sample markup, the int1 property is incremented by 10 instead of 1 which is the default value.

mm8
  • 163,881
  • 10
  • 57
  • 88
  • I didn't get the chance to try it yet but it looks like a solution, thanks! Edit: Actually, the screen came empty only with a PropertyGrid. Any idea? – hebele May 21 '18 at 12:36
  • I don't see anything, no, see here: https://cdn1.imggmi.com/uploads/2018/5/21/c859a98a6ba8a498c91e01c4836ad227-full.png – hebele May 21 '18 at 12:44
  • The Sample class must of course have a property called "int1". Otherwise you will have to replace "int1" with whatever the name of your property is. – mm8 May 21 '18 at 12:45
  • My bad sorry, the line where I set the SelectedObject was commented. Thanks again! – hebele May 21 '18 at 12:51