C# DataTemplate中的Silverlight组合框
我在xaml中为c类定义了一个数据模板,如下所示C# DataTemplate中的Silverlight组合框,c#,silverlight,data-binding,combobox,telerik,C#,Silverlight,Data Binding,Combobox,Telerik,我在xaml中为c类定义了一个数据模板,如下所示 <DataTemplate x:Key="ApplicationTemplate"> <StackPanel Orientation="Vertical"> <telerik:RadComboBox DisplayMemberPath="Name" ItemsSou
<DataTemplate x:Key="ApplicationTemplate">
<StackPanel Orientation="Vertical">
<telerik:RadComboBox DisplayMemberPath="Name"
ItemsSource="{Binding CurrentItem.Apps, RelativeSource={RelativeSource FindAncestor, AncestorType=telerik:RadDataForm}}"
IsEnabled="{Binding IsReadOnly, RelativeSource={RelativeSource AncestorType=ContentControl}, Converter={StaticResource BooleanInverterConverter}}" />
</StackPanel>
</DataTemplate>
在视图模型中,我有:
public IList<InteractiveApplicationModel> Apps
{
get
{
return new List<InteractiveApplicationModel>()
{
new InteractiveApplicationModel(null,null,null,null),
new InteractiveApplicationModel("name","type","url","image"),
new InteractiveApplicationModel("name2","type2","url2","image2")
};
}
}
然后我有一个表单页面,它加载包含InteractiveApplicationModel对象的复杂对象,并使用数据模板显示这些对象
除了一件事,一切都在运转。我需要组合框的选定值与复杂对象中InteractiveApplicationModel对象的值相同
“我的复杂对象”中最多可以有5个InteractiveApplicationModel对象。您必须绑定RadComboBox上的SelectedItem属性
SelectedItem="{Binding SelectedInteractiveApplicationModel, [.... ancestor ....] Mode=TwoWay}"
使用ViewModel上的选定特性
public InteractiveApplicationModel SelectedInteractiveApplicationModel
{
get { return GetProperty(() => SelectedInteractiveApplicationModel); }
set { SetProperty(() => SelectedInteractiveApplicationModel, value); }
}
问题是,没有selectedItem,有一个复杂的对象,其中包含InteractiveApplicationModel类的多个实例,对于每个实例,表单页面都会显示一个组合框。在本例中,它是5个组合框,所选项目与InteractiveApplicationModel的值相对应。这最后一部分是我试图实现的。如果您想打开SelectedItem在VIewModel端,您至少需要一个InteractiveApplicationModel属性才能绑定到。。。
public InteractiveApplicationModel SelectedInteractiveApplicationModel
{
get { return GetProperty(() => SelectedInteractiveApplicationModel); }
set { SetProperty(() => SelectedInteractiveApplicationModel, value); }
}