【发布时间】:2014-03-17 15:58:43
【问题描述】:
我有一个combobox,我想在其中显示几个对象并返回enum 值。根据外部数据在视图中生成combobox的随机数。 combobox 按预期工作,但是在我打开它们中的任何一个然后打开另一个之后,然后是我第一次打开的那个,然后第一个中的项目无法访问。(这些项目仍然存在,但 @987654325 @ 菜单为空)。
为了清楚起见,我一步一步地把我的行动放在这里:
- 我打开
ComboBox1。我可以看到所有项目。 - 我打开
ComboBox2。我可以看到所有项目。 - 我尝试打开
ComboBox1。它的下拉菜单中没有任何项目。 - 我打开
ComboBox3。我可以看到所有项目。 - 所有项目都从
ComboBox1和ComboBox2中消失。
我猜这个问题是由ItemsSource 的路径损坏引起的,但我不知道如何避免它。
<DataTemplate x:Key="CustomizedComboBox">
<StackPanel Width="70" Margin="0,0,12,0">
<ComboBox
SelectedIndex="{Binding Path=Type, Mode=TwoWay, Converter={vm:SelectedItemConverter}}"
ItemsSource="{StaticResource IconsAndLabelsArray}"
MinHeight="50"/>
</ComboBox>
</StackPanel>
IconsAndLabelsArray:
<x:Array x:Key="IconsAndLabelsArray" Type="{x:Type StackPanel}" >
<StackPanel Orientation="Horizontal">
<Image Height="42"
VerticalAlignment="Top"
Source="/ProjectName;image1.png"
Stretch="Uniform" />
<Label VerticalAlignment="Center" Content="Image1 Label" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<Image Height="42"
VerticalAlignment="Top"
Source="/ProjectName;image2.png"
Stretch="Uniform" />
<Label VerticalAlignment="Center" Content="Image2 Label" />
</StackPanel>
【问题讨论】:
标签: wpf vb.net xaml combobox datatemplate