XAML 在ComboBox WPF中禁用突出显示文本

ua4mk5z4  于 2024-01-04  发布在  其他
关注(0)|答案(1)|浏览(112)

我在我的组合框中添加了一些显示文本,但我想删除高亮显示它的功能。当光标悬停在文本上时,光标会自动显示为“文本”样式的光标。我尝试按照另一个答案建议执行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>

字符串

ebdffaop

ebdffaop1#

我不确定我是否正确理解了你的意思,但是试试这个实现。

<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>

字符串

**P.S.**从概念上讲,这里使用按钮的原因并不清楚。ComboBox是一个控件,即从集合中选择元素的控件。如果你只是需要一个按钮的下拉列表,那么你应该使用Expander甚至Menu。

相关问题