如何确定 ComboBox 项目是在下拉列表中还是在其中

How to find out if ComboBox item is in dropdown list or inside it

我希望 ComboBox 中的选定项目看起来不同于它在下拉列表中的实例。

    <ComboBox ItemsSource="{Binding ViewList}" SelectedItem="{Binding SelectedView}">
        <ComboBox.Resources>
            <DataTemplate DataType="{x:Type vm:View}">
                <StackPanel Orientation="Horizontal">
                    <c:Icon x:Name="Icon" IconShape="{DynamicResource z.Users}" Margin="5,0" Background="{Binding Foreground, RelativeSource={RelativeSource Self}}"/>
                    <StackPanel>
                        <StackPanel>
                            <TextBlock x:Name="CurrentView" Text="Current View"
                                       Foreground="{DynamicResource Pallete.Primary.Brighter}"
                                       Visibility="{Binding IsSelected, Converter={StaticResource bool2VisibilityConverter}}"/>
                            <TextBlock x:Name="Title" Text="{Binding Title}"/>
                        </StackPanel>
                    </StackPanel>
                </StackPanel>
                <DataTemplate.Triggers>
                    <DataTrigger Binding="{Binding Type}" Value="SeparatorView">
                        <Setter TargetName="Icon" Property="Visibility" Value="Collapsed"/>
                        <Setter TargetName="Title" Property="FontWeight" Value="Bold"/>
                    </DataTrigger>
                    <DataTrigger Binding="{Binding Type}" Value="YearView">
                        <Setter TargetName="Icon" Property="IconShape" Value="{DynamicResource z.Bookmark}"/>
                    </DataTrigger>
                </DataTemplate.Triggers>
            </DataTemplate>
        </ComboBox.Resources>
    </ComboBox>

我可以在 CurrentView 的可见性 属性 或触发器中使用什么吗?

这是您可以修改 TextBlockForeground 的示例,当它在 ComboBox 中被选中时使用 DataTrigger:

<ComboBox ItemsSource="{Binding ListOfStrings}">
    <ComboBox.Resources>
        <DataTemplate DataType="{x:Type sys:String}">
            <TextBlock x:Name="txt" Text="{Binding}" Foreground="Red" />
            <DataTemplate.Triggers>
                <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=ComboBoxItem}}" Value="{x:Null}">
                    <Setter TargetName="txt" Property="Foreground" Value="Green"/>
                </DataTrigger>
            </DataTemplate.Triggers>
        </DataTemplate>
    </ComboBox.Resources>
</ComboBox>

我相信以下是您要找的:

<DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=ComboBoxItem}}" Value="{x:Null}">