Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WPF组合框所选项目_C#_Wpf_Combobox_Selecteditem - Fatal编程技术网

C# WPF组合框所选项目

C# WPF组合框所选项目,c#,wpf,combobox,selecteditem,C#,Wpf,Combobox,Selecteditem,我有一个组合框,其中很少有项目显示为图像和文本(每个项目并排放置)。现在,当我从组合框列表中选择一个项目时,我想在组合框selecteditem区域显示其他内容(而不是相同的图像和文本),可能是另一个文本或另一个图像 我有没有办法做到这一点 有几种可能的方法,其中一种是使用。最简单的方法是将IsSelected触发器添加到Combobox的DataTemplate(Itemstemplate)中,我认为您有两组可视元素,一组用于常规数据显示,另一组用于选定的可视元素,在ComboboxItem上

我有一个组合框,其中很少有项目显示为图像和文本(每个项目并排放置)。现在,当我从组合框列表中选择一个项目时,我想在组合框selecteditem区域显示其他内容(而不是相同的图像和文本),可能是另一个文本或另一个图像


我有没有办法做到这一点

有几种可能的方法,其中一种是使用。

最简单的方法是将IsSelected触发器添加到Combobox的DataTemplate(Itemstemplate)中,我认为您有两组可视元素,一组用于常规数据显示,另一组用于选定的可视元素,在ComboboxItem上设置IsSelected属性时,需要隐藏常规视觉效果,并显示另一个。这里真正的技巧是找到使用FindAncestor选择的即时ComboBoxItem用户

<DataTemplate x:Key="yourDataTemplate">
 <Grid x:Name="regularVisuals" > ... </Grid>
 <Grid x:Name="selectedVisuals" Visibility="Collapsed"> ... </Grid>
<DataTemplate.Triggers>
    <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type ComboBoxItem}},Path=IsSelected}" Value="True">
        <Setter TargetName="regularVisuals" Property="Visibility" Value="Visible"/>
        <Setter TargetName="selectedVisuals" Property="Visibility" Value="Collapsed"/>
    </DataTrigger>
</DataTemplate.Triggers>

... 
... 

我想更改组合框收拢时的外观,并且组合框上显示selecteditem。两个Setter的TargetName是否都应该真正读取selectedVisuals?难道一个不应该是正规的视觉工具吗?