我有点坚持实现一种 propertyGrid 类型的控件,但在我的情况下,对于给定的属性,我在之前和之后都有价值。例如,如果属性是名称,则它具有两个值,例如 name before 和 name after。
class Person
{
#region class constructor
/// <summary>
/// class constructor
/// </summary>
/// <param name="_person"></param>
public Person(string before,string after)
{
this.nameBefore = before; // assign beforename to namebefore
this.nameAfter = after; // assign aftername to nameAfter
}
#endregion class constructor
#region properties
/// <summary>
/// Name property
/// </summary>
private string nameBefore;
/// <summary>
/// public Property
/// for nameBefore
/// </summary>
public string NameBefore
{
get { return nameBefore; }
set { nameBefore = value; }
}
/// <summary>
/// name property after
/// </summary>
private string nameAfter;
/// <summary>
/// public property for nameAfter
/// </summary>
public string NameAfter
{
get { return nameAfter; }
set { nameAfter = value; }
}
#endregion properties
}
我需要公开这个类的所有属性,这些属性可能在之前和之后都有值。这些值是在外部设置的。我需要像属性网格一样填充这些值。但就我而言,我还有一个额外的列(之后的值)。
这就是我的 xaml 的样子:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="20" />
<RowDefinition />
</Grid.RowDefinitions>
<TextBlock Background="Gray" Padding="5,2,5,5" Grid.Column="0" Grid.Row="0" Text="Property" />
<TextBlock Background="Gray" Padding="5,2,5,5" Grid.Column="1" Grid.Row="0" Text="Before" />
<TextBlock Background="Gray" Padding="5,2,5,5" Grid.Column="2" Grid.Row="0" Text="After" />
<TextBlock Grid.Column="0" Grid.Row="1" Text="Name" />
<TextBlock Grid.Column="1" Grid.Row="1" Text="{Binding Before }" />
<TextBlock Grid.Column="2" Grid.Row="1" Text="{Binding After }" />
</Grid>
我需要这样的东西
属性窗口
我们能以编程方式得到这样的东西吗?我的意思是拥有一个属性及其多重价值。它也可以是多键值字典吗?