我试图将不同的增量值分配给对象的不同字段。例如,考虑一个类拥有 int1
和 int2
,当我将 PropertyGrid
的 ShowAdvancedOptions
设置为 true 时>,整数向上向下按钮放入文本框中没有问题。但我希望能够编辑数字单独增加的数量。有什么办法可以实现这一点吗?
编辑:
这是代码:
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>
和示例类:
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
}
最佳答案
您可以为每个属性定义一个自定义EditorTemplate
:
<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>
在上面的示例标记中,int1
属性增加 10
,而不是默认值 1
。
关于c# - XCeed PropertyGrid 自定义 IntegerUpDown,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50443733/