【发布时间】:2019-08-02 18:38:18
【问题描述】:
我有一个组合框,允许用户从一组图像中进行选择。由于图像的大小,一旦选择了图像,我不想在组合框中显示图像。选择项目时,我只是想在Combobox中显示任何内容。
到目前为止,我已经尝试将 selectedImageIndex 设置为 -1,一旦在用户进行选择时设置了 selectedImageSource,但这不起作用,因为默认情况下,[0] 处的第一个图像仍显示在组合框中。我正在使用 MVVM。
XAML
<ComboBox Grid.Row="1" SelectedIndex="{Binding SelectedImageIndex}" ItemsSource="{Binding SymbolImageCollection}">
<ComboBox.ItemTemplate>
<DataTemplate>
<Image Source="{Binding Img}" Width="50" Height="50"/>
</DataTemplate>
</ComboBox.ItemTemplate>
<ComboBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Width="300" HorizontalAlignment="Left"/>
</ItemsPanelTemplate>
</ComboBox.ItemsPanel>
</ComboBox>
查看模型
public ObservableCollection<SymbolImage> SymbolImageCollection { get { return AppearanceLayerProperties.Instance.SymbolImageCollection; } }
private string _selectedImageSource;
public string SelectedImageSource
{
get { return _selectedImageSource; }
set
{
SetProperty(ref _selectedImageSource, value);
//SelectedImageIndex = -1;
}
}
private int _selectedImageIndex;
public int SelectedImageIndex
{
get { return _selectedImageIndex; }
set
{
var selectedImage = AppearanceLayerProperties.Instance.SymbolImageCollection[value].ImgSource;
SelectedImageSource = selectedImage;
SetProperty(ref _selectedImageIndex, -1);
}
}
【问题讨论】:
-
不是该问题的重复项 - 我需要在选择项目后将所选项目隐藏在组合框中显示的内容中。这个问题是关于隐藏下拉列表中显示的集合中的项目。