【发布时间】:2011-05-18 13:10:26
【问题描述】:
在 Silverlight、MVVM 中,我必须创建一个属性窗口,但我只有一个
List<AProperty> 对象,其中AProperty 是一个带有一些子类的抽象类。
我想将它绑定到 Silverlight 控件(但绑定到哪个控件?),但有一些条件:
- 一些子属性必须显示为文本框,一些显示为复选框,一些显示为组合框。它来自动态类型。
- AProperty 类有一个
PropertyGroup和一个Name字段。顺序必须是字母 (PropertyGroup > Name)
任何想法或工作示例?
我的代码:
public abstract class AProperty {
private String _Name;
private String _Caption;
private String _PropertyGroup;
public String Name {
get { return _Name; }
set { _Name = value; }
}
public String Caption {
get { return _Caption; }
set { _Caption = value; }
}
public String PropertyGroup {
get { return _PropertyGroup; }
set { _PropertyGroup = value; }
}
}
List<AProperty> Properties;
还有 xaml:
<ListBox ItemsSource="{Binding ... Properties ...}">
<!-- Here order the items -->
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Width="250"
Text="{Binding Path=Caption}" />
<!-- And here need I a textbox, or a checkbox, or a combobox anyway -->
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
我发现值转换器仅适用于控件属性,而不适用于整个堆栈面板内容。
【问题讨论】:
-
问题仍然存在,是否可以对xaml代码中的元素进行排序?
标签: silverlight mvvm bind