问题描述
||
我有一个集合及其结构:
public class FunctionListBindStructure : AttributeBase
{
public FunctionListBindStructure() : base(true) { }
//this represents one row of the collection
public MyFunction Function { get; set; }
public string Name { get; set; }
}
public class FunctionListBind : AttributeListBase
{
//this represents
public ObservableCollection<FunctionListBindStructure> FunctionList { get; set; }
public FunctionListBind()
: base(true)
{
FunctionList = new ObservableCollection<FunctionListBindStructure>();
}
public override IList GetList()
{
return FunctionList as IList;
}
}
此类使用框架,该框架为CLR属性Function.DisplayName作为\“ FunctionDisplayNameProperty \”生成依赖项属性。
在我的示例视图中,我将此集合绑定到ListBox
ListBox ItemsSource=\"{Binding MyModel.FunctionListBind.FunctionList}\" Height=\"52\" HorizontalAlignment=\"Left\" Margin=\"136,157,0\" Name=\"listBox1\" VerticalAlignment=\"Top\" Width=\"130\" >
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text=\"{Binding FunctionDisplayNameProperty,Mode=TwoWay}\"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
现在的问题是,列表中仅显示集合的最后一个项目……以前的项目仅以空格显示;尽管我非常确定(通过调试器),但前几行的依赖项属性(当它们注册时及其值集)应具有非初始值。如果我直接引用相应的CLR属性(Function.DisplayName),一切正常。
我的问题:我在这里犯一个设计错误吗?依赖项属性不应该用作行类型吗?我对非收集使用了相同的模式,并且可以正常工作。这也是为什么我要对集合使用相同的方法的原因(我可以使用exisitng代码行的90%来生成和设置Dependeny Properties)。
感谢您提供任何提示,还感谢如何调试(如果不是设计错误)调试Dependency Property绑定。
解决方法
这只是我的框架编码的错误。我已经将依赖项属性定义为实例属性,而不是静态属性。现在一切正常。