我有一些让我抓狂的XAML代码。它首先为一个未引用的值添加一个虚拟项。
为此,我必须实现
CollectionViewSource
和a
CompositeCollection
。
现在我无法选择第一个组合框项目,它出现了,但我无法选择它,因为我设置了
DisplayMemberPath
在XAML中(我想是这样)。此外,分隔符看起来也不符合预期。
让我向您展示:
如果我不设置XAML
DisplayMemberPath
,我可以使用虚拟项,但绑定项显示不正确:
XAML:
<ComboBox x:Name="G_cb_content_zuordnung"
Margin="165,0,0,0"
Grid.Row="1"
SelectedIndex="0"
VerticalAlignment="Top"
DisplayMemberPath="PartnerID"
HorizontalAlignment="Left"
Width="119">
<ComboBox.Resources>
<CollectionViewSource x:Key="ComboCollection" Source="{Binding Path=mySelectedItem.Stammkinder}" />
</ComboBox.Resources>
<ComboBox.ItemsSource>
<CompositeCollection>
<ComboBoxItem Content="Ohne Stammnummer" Name="NoPID" />
<Separator />
<CollectionContainer Collection="{Binding Source={StaticResource ComboCollection}, Mode=OneWay}" />
</CompositeCollection>
</ComboBox.ItemsSource>
</ComboBox>
我只需要一个虚拟/占位符组合框项,它显示在
ObservableCollection<myClass>
.我的思维方式是不是错了?有更聪明的解决方案吗?我的解决方案中是否遗漏了什么?