【发布时间】:2013-11-18 06:49:34
【问题描述】:
我还是 MVVM(和 C#)的新手,所以如果我的问题不清楚,请告诉我,我会更新/澄清。
我的xaml 中有一个ListView,代码如下:
<ListView.Resources>
<local:IndexConverter x:Key="IndexConverter" />
<DataTemplate x:Key="OrdinalColumnDataTemplate">
<TextBlock Text="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ListViewItem},
Converter={StaticResource ResourceKey=IndexConverter}}" HorizontalAlignment="Right" />
</DataTemplate>
</ListView.Resources>
<ListView.View>
<GridView x:Name="gridView3">
<GridViewColumn Header="#" CellTemplate="{StaticResource ResourceKey=OrdinalColumnDataTemplate}" />
<GridViewColumn DisplayMemberBinding="{Binding Name, NotifyOnTargetUpdated=True, UpdateSourceTrigger=PropertyChanged}" Header="Name" />
<GridViewColumn DisplayMemberBinding="{Binding License, NotifyOnTargetUpdated=True, UpdateSourceTrigger=PropertyChanged}" Header="License" />
</GridView>
</ListView.View>
它按预期工作,它填充了每个元素的Name 和License 属性。
现在我想添加一个ComboBox 并用ListView 中显示的相同元素的唯一Names 填充它。
问题 1:我已经测试了下面的代码,但它不起作用,xml 应该是什么样子?
<ComboBox Name="filterUserComboBox" ItemsSource="{Binding Path=licenseListView, ElementName=Name}"></ComboBox>
问题 2:当上述工作正常时,如何将“全部”(或单个空元素)元素添加到 ComboBox?
【问题讨论】:
-
为什么不在 ResourceList 的索引 0 处插入一个新条目来表示“全部”选项?
-
也许这个问题就是你想做的:stackoverflow.com/questions/1426050/…
-
@roqz,不,这完全是另一个问题。
-
可以肯定的是,您希望组合框中的空元素像空值一样吗?
-
@dennisschütz,是的。后缀为空元素。
标签: c# data-binding mvvm combobox