禁用组合框 WPF 中的突出显示文本

问题描述 投票:0回答:1

我已在组合框中添加了一些显示文本,但我想删除突出显示它的功能。当鼠标悬停在文本上时,光标自动显示为“文本”样式光标。我尝试按照另一个答案的建议执行 IsHitTestVisable=false ,但这只是完全消除了与组合框交互的能力。

<Window x:Class="msmExe.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:msmExe"
        mc:Ignorable="d"
        Title="Home" Height="450" Width="800">
    <Grid Background="Black">
        <Image HorizontalAlignment="Left" Height="446" Margin="33,0,0,0" VerticalAlignment="Top" Width="831" Opacity="0.695" Source="./Images/homepage.png"/>
        <ComboBox x:Name="cboDiskInstructions" HorizontalAlignment="Right" Height="55" Margin="0,172,86.333,0" VerticalAlignment="Top" Width="190" RenderTransformOrigin="0.55,2.63" Background="#FFD1D1D1" IsEditable="True" IsReadOnly="True" Text="Instructions" VerticalContentAlignment="Center" HorizontalContentAlignment="Center"  FontFamily="Sans Serif Collection" FontSize="16" FontWeight="Bold" Opacity="0.9" Focusable="False" IsMouseDirectlyOverChanged="cboInstructions_MouseOverDirectlyChanged" MouseEnter="cboInstructions_MouseEnter" >
            <ComboBox.ItemContainerStyle>
                <Style TargetType="{x:Type ComboBoxItem}">
                    <Setter Property="Background" Value="#FFE4E4E4"/>
                    <Setter Property="BorderBrush" Value="#FFE4E4E4"/>
                </Style>
            </ComboBox.ItemContainerStyle>
            <Button x:Name="Instructions1" Content="Instructions 1" Width="170" BorderBrush="{x:Null}" Background="{x:Null}" Click="Instructions1_Click"/>
            <Button x:Name="Instructions2" Content="NFS UNDERGROUND" Width="170" BorderBrush="{x:Null}" Background="{x:Null}" Click="Instructions2_Click"/>
        </ComboBox>
        <Button x:Name="buttonMain" Content="TEXT" HorizontalAlignment="Left" Height="55" Margin="83,172,0,0" VerticalAlignment="Top" Width="190" Background="White" FontFamily="Sans Serif Collection" FontSize="16" FontWeight="Bold" Opacity="0.9" Click="buttonMain_Click"/>
    </Grid>
</Window>
c# wpf xaml
1个回答
0
投票

我不确定我是否理解正确,但尝试一下这个实现。

    <ComboBox SelectedIndex="0" VerticalAlignment="Center" HorizontalAlignment="Center">
        <ComboBox.ItemContainerStyle>
            <Style TargetType="{x:Type ComboBoxItem}">
                <Setter Property="Background" Value="#FFE4E4E4"/>
                <Setter Property="BorderBrush" Value="#FFE4E4E4"/>
            </Style>
        </ComboBox.ItemContainerStyle>
        <ComboBoxItem Content="Instructions" Visibility="Collapsed"/>
        <Button Content="Instructions 1"/>
        <Button Content="NFS UNDERGROUND"/>
    </ComboBox>
© www.soinside.com 2019 - 2024. All rights reserved.