WPF删除菜单项和列表视图上的鼠标悬停/悬停边框

WPF删除菜单项和列表视图上的鼠标悬停/悬停边框,wpf,xaml,Wpf,Xaml,我已经到处寻找答案,但还没有找到实现我需要做的事情的方法,所以我想我应该问自己一个问题 我的UserControl中有两个菜单以及一个ListView。每当鼠标悬停在任何菜单项(在本例中为下图中的“结束日”按钮)或listview上时,控件周围都会出现一个薄边框,当鼠标移到其他位置时,该边框就会消失。我不知道这叫什么,也不知道如何定位它(在XAML或Blend中),但我很想学习如何在menuitems和listview中禁用它(以及其他控件,如果有统一的方法),最好是在XAML中。我觉得这很烦人

我已经到处寻找答案,但还没有找到实现我需要做的事情的方法,所以我想我应该问自己一个问题

我的UserControl中有两个菜单以及一个ListView。每当鼠标悬停在任何菜单项(在本例中为下图中的“结束日”按钮)或listview上时,控件周围都会出现一个薄边框,当鼠标移到其他位置时,该边框就会消失。我不知道这叫什么,也不知道如何定位它(在XAML或Blend中),但我很想学习如何在menuitems和listview中禁用它(以及其他控件,如果有统一的方法),最好是在XAML中。我觉得这很烦人。如果可以的话,请帮帮我

更新:我的列表视图:

<ListView ItemsSource="{Binding Adventurers}"
              Name="AdvListView"
              ScrollViewer.CanContentScroll="False"
              Background="Gray"
              BorderBrush="Transparent"
              Grid.Column="1"
              Grid.ColumnSpan="3"
              Grid.Row="2">

        <i:Interaction.Triggers>
            <i:EventTrigger EventName="SelectionChanged">
                <cmd:EventToCommand Command="{Binding Mode=OneWay, Path=ShowAdvCommand}"
                                    CommandParameter="{Binding ElementName=AdvListView, Path=SelectedItem}"
                                    PassEventArgsToCommand="True" />
            </i:EventTrigger>
        </i:Interaction.Triggers>
        <ListView.View>
            <GridView>
                <GridViewColumn Width="Auto" Header="Name" DisplayMemberBinding="{Binding Name}" />
                <GridViewColumn Width="Auto" Header="Level" DisplayMemberBinding="{Binding Level}"/>
            </GridView>
        </ListView.View>
    </ListView>

我的菜单:

<Menu Background="#FFA9D1F4"
          Grid.ColumnSpan="5" 
          IsMainMenu="False">
        <Menu.ItemsPanel>
            <ItemsPanelTemplate>
                <DockPanel HorizontalAlignment="Stretch" />
            </ItemsPanelTemplate>
        </Menu.ItemsPanel>
        <MenuItem Header="File"
                  Focusable="False"
                  FontFamily="Pericles"
                  FontSize="16"
                  VerticalAlignment="Center"
                  HorizontalAlignment="Left">


            <MenuItem Header="Save" 
                      Command="{Binding SaveGame}" />

            <MenuItem Header="Load" 
                      Command="{Binding LoadGame}" />

            <MenuItem Header="Quit" />
        </MenuItem>

        <Button Content="End Day" 
                Command="{Binding EndDayCommand}" 
                Focusable="False"
                FontFamily="Pericles"
                FontSize="16"
                VerticalAlignment="Center"
                HorizontalAlignment="Left" />

        <Button Content="Load" 
                Command="{Binding LoadGame}" 
                Focusable="False"
                FontFamily="Pericles"
                FontSize="16"
                VerticalAlignment="Center"
                HorizontalAlignment="Left" />

        <Button Content="Save" 
                Command="{Binding SaveGame}" 
                Focusable="False"
                FontFamily="Pericles"
                FontSize="16"
                VerticalAlignment="Center"
                HorizontalAlignment="Left" />

        <Label Content="{Binding GameDate}"
               Focusable="False"
               ContentStringFormat="{}{0:d\/M\/y}"
               FontFamily="Pericles"
               FontSize="16"
               VerticalAlignment="Center"
               HorizontalAlignment="Right" />
    </Menu>

在blend中,您可以右键单击按钮,然后单击“编辑模板副本”或类似内容(不是逐字)

它将打开按钮的实际模板,在那里您可以编辑视觉状态。在这里,您可以完全删除或编辑悬停效果


很抱歉,我无法向您提供更多详细信息。

问题是您的按钮位于菜单定义中,这不是菜单的常用用法,因为它应该包含菜单项。我相信您需要一个包含一些按钮和菜单的“菜单”,我为您提供了一个简单的解决方案,您应该根据您的特定代码进行调整:

另一个不推荐的解决方案是深入菜单项和菜单默认控件模板,并“从头开始”编写它们,因为您无法在局部事件中覆盖默认样式,下面是一个如何不覆盖默认样式的示例(同样,在这种情况下,强烈不推荐):


编辑:

我做了一些重构,所以它看起来像一个完整解决方案的“好看”菜单栏,请尝试一下

从你的列表来看,我相信这个问题是以一种非常相似的方式解决的

    <Window x:Class="WpfApplication4.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <Grid.Resources>
            <Style TargetType="{x:Type Button}">
                <Setter Property="Margin" Value="5"></Setter>
            </Style>
        </Grid.Resources>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="Auto"/>
        </Grid.ColumnDefinitions>
        <StackPanel Background="#FFA9D1F4" Grid.Row="0" Grid.ColumnSpan="2" Orientation="Horizontal">
            <Menu 
         Background="#FFA9D1F4"
              BorderBrush="{x:Null}"
          IsMainMenu="False">
                <Menu.ItemsPanel>
                    <ItemsPanelTemplate>
                        <DockPanel HorizontalAlignment="Stretch" />
                    </ItemsPanelTemplate>
                </Menu.ItemsPanel>
                <Menu.Resources>
                    <Style TargetType="{x:Type MenuItem}">
                        <Setter Property="Background" Value="#FFA9D1F4"></Setter>
                    </Style>
                </Menu.Resources>
                <MenuItem Header="File"
                  Focusable="False"
                  FontFamily="Pericles"
                  FontSize="16"
                  VerticalAlignment="Center"
                  HorizontalAlignment="Left">


                    <MenuItem Header="Save" 
                              Background="#FFA9D1F4"
                      Command="{Binding SaveGame}" />

                    <MenuItem Header="Load" 
                              Background="#FFA9D1F4"
                      Command="{Binding LoadGame}" />

                    <MenuItem Header="Quit" />
                </MenuItem>
            </Menu>

            <Button Content="End Day" 
                Command="{Binding EndDayCommand}" 
                Focusable="False"
                FontFamily="Pericles"
                FontSize="16"
                VerticalAlignment="Center"
                HorizontalAlignment="Left" />



            <Button Content="Load" 
                Command="{Binding LoadGame}" 
                Focusable="False"
                FontFamily="Pericles"
                FontSize="16"
                VerticalAlignment="Center"
                HorizontalAlignment="Left" />

                <Button Content="Save" 
                Command="{Binding SaveGame}" 
                Focusable="False"
                FontFamily="Pericles"
                FontSize="16"
                VerticalAlignment="Center"
                HorizontalAlignment="Left" />

        </StackPanel>
        <Label Margin="0" Grid.Row="0" Grid.Column="1" Content="1/1/13"
               Focusable="False"
               ContentStringFormat="{}{0:d\/M\/y}"
               FontFamily="Pericles"
               FontSize="16"
               VerticalAlignment="Center"
               HorizontalAlignment="Right" />

    </Grid>
</Window>


对我有效的方法是像这样使用IshitteVisible标记:

<Menu IsHitTestVisible="False" > ... </Menu>
。。。
您还可以将其与
Focusable=“False”


基本上,我使用它来完全禁用用户可以单击菜单的功能(这正是我的用例所需要的)。

您能提供一些xaml的代码片段吗?由于关注控件的偏差及其样式(显式或隐式设置),我更新了我的帖子。太好了,没有样式吗?你确定?根据图片,有涉及的样式,请检查xaml中的父节点,以查找包含样式的资源节点或所用的usercontrol资源字典。我的xaml中没有任何涉及样式的内容。我已经研究过了,而此更改涉及修改默认模板,我将为您发布答案,但我必须警告你,这将是一个漫长的密码。
<Menu IsHitTestVisible="False" > ... </Menu>