我使用属性网格来显示软件对象的属性。 显示的属性之一是集合中元素的ID。 在属性网格中,集合显示为带有选定元素的组合框。
属性网格XAML:
<xctk:PropertyGrid x:Name="_propertyGrid" Margin="0,2,0,0" AutoGenerateProperties="False" Grid.Row="1" Background="LightGray" ShowTitle="False"
PropertyValueChanged="_propertyGrid_PropertyValueChanged" SelectedObjectChanged="_propertyGrid_SelectedObjectChanged"
ShowSummary="False" ShowDescriptionByTooltip="True" Grid.RowSpan="2" IsManipulationEnabled="True" UseLayoutRounding="True"
SelectedPropertyItemChanged="_propertyGrid_SelectedPropertyItemChanged" >
<xctk:PropertyGrid.PropertyDefinitions>
<xctk:PropertyDefinition TargetProperties="Id" />
<xctk:PropertyDefinition TargetProperties="BGColor" Category=" Colors" DisplayName="Background" DisplayOrder="1"/>
<xctk:PropertyDefinition TargetProperties="FGColor" Category=" Colors" DisplayName="Foreground" DisplayOrder="2" />
<xctk:PropertyDefinition TargetProperties="PosX" Category=" Layout" DisplayOrder="0"/>
<xctk:PropertyDefinition TargetProperties="PosY" Category=" Layout" DisplayOrder="1"/>
<xctk:PropertyDefinition TargetProperties="Width" Category=" Layout" DisplayOrder="2"/>
<xctk:PropertyDefinition TargetProperties="Height" Category=" Layout" DisplayOrder="3"/>
<xctk:PropertyDefinition TargetProperties="Type" DisplayOrder="0"/>
<!--<xctk:PropertyDefinition TargetProperties="SourceTable" DisplayOrder="10" DisplayName="Ext Format" />-->
<xctk:PropertyDefinition TargetProperties="StrSourceTable" DisplayOrder="10" DisplayName="Ext Format" />
<xctk:PropertyDefinition TargetProperties="FontSizes" DisplayOrder="4"/>
<!-- Label Specific Properties -->
<xctk:PropertyDefinition TargetProperties="Text" DisplayOrder="4"/>
<!-- Data Properties -->
<xctk:PropertyDefinition TargetProperties="Data" DisplayOrder="3"/>
<xctk:PropertyDefinition TargetProperties="Data2" DisplayOrder="4" DisplayName="Data Y" />
// THE ID SIMPLE TOUCH PROPERTY HERE :
<xctk:PropertyDefinition TargetProperties="IDActionSimpleTouch" DisplayOrder="3" DisplayName="Simple Touch" />
<xctk:PropertyDefinition TargetProperties="IDActionDoubleTouch" DisplayOrder="4" DisplayName="Double Touch" />
<xctk:PropertyDefinition TargetProperties="IDActionLongTouch" DisplayOrder="5" DisplayName="Long Touch" />
绑定对象中的属性:
[XmlIgnore]
private UInt16 _IDActionSimpleTouch = 0;
[XmlAttribute]
[ItemsSource(typeof(UserEventItemSource))]
[RefreshProperties(RefreshProperties.All)]
public UInt16 IDActionSimpleTouch
{
get { return _IDActionSimpleTouch; }
set
{
_IDActionSimpleTouch = value;
this.PropertyChangedNotify("IDActionSimpleTouch");
}
}
商品来源定义:
class UserEventItemSource : IItemsSource
{
public ItemCollection GetValues()
{
ItemCollection ActionsDatas = new ItemCollection();
if (UserEventInfos.ListeUserEvent.Find(x => x == "OFF") == null) UserEventInfos.ListeUserEvent.Insert((UInt16) 0, "OFF");
foreach (string s in UserEventInfos.ListeUserEvent) if(s != null) ActionsDatas.Add((UInt16)UserEventInfos.ListeUserEvent.IndexOf(s), s);
return ActionsDatas;
}
}
属性网格中的结果是:
问题是当我在此列表中添加新元素时。它不显示新元素。 我不知道在发出属性更改通知时如何强制更新itemsource集合。
谢谢您的帮助