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
移除wpf按钮鼠标上方的奇怪行为_Wpf_Xaml_Button_Styles_Mouseover - Fatal编程技术网

移除wpf按钮鼠标上方的奇怪行为

移除wpf按钮鼠标上方的奇怪行为,wpf,xaml,button,styles,mouseover,Wpf,Xaml,Button,Styles,Mouseover,我为一个虚拟问题争论了好几个小时 在wpf中,我希望覆盖按钮的行为,并且在达到我想要的基本行为的那一刻(特定颜色) 但我不能简单地说:在鼠标上方添加下划线样式! 我可以添加下划线,但无法删除文本周围的正方形 我使用的样式是: <Style TargetType="Button"> <Setter Property="Foreground" Value="{DynamicResource {x:Static vs_shell:EnvironmentColors.Co

我为一个虚拟问题争论了好几个小时

在wpf中,我希望覆盖
按钮的行为,并且在达到我想要的基本行为的那一刻(特定颜色)

但我不能简单地说:在鼠标上方添加下划线样式! 我可以添加下划线,但无法删除文本周围的正方形

我使用的样式是:

 <Style TargetType="Button">
    <Setter Property="Foreground" Value="{DynamicResource {x:Static vs_shell:EnvironmentColors.CommandBarMenuLinkTextBrushKey}}"></Setter>
    <Setter Property="Cursor" Value="Hand"></Setter>
    <Setter Property="Background" Value="Transparent"></Setter>
    <Setter Property="BorderThickness" Value="0"></Setter>
    <Style.Triggers>
        <Trigger Property="IsMouseOver" Value="True">
            <Setter Property="Background" Value="Transparent"/>
            <Setter Property="ContentTemplate">
                <Setter.Value>
                    <DataTemplate>
                        <TextBlock TextDecorations="Underline" Text="{TemplateBinding Content}" Background="Transparent"/>
                    </DataTemplate>
                </Setter.Value>
            </Setter>
        </Trigger>
    </Style.Triggers>
</Style>

有什么想法/建议吗


谢谢

也许这会帮助你:

它涉及ListViewItems,但您可以在按钮或任何其他WPF控件上应用此机制


祝你好运

将此setter添加到样式中:

<Setter Property="Template">
    <Setter.Value>
        <ControlTemplate TargetType="{x:Type Button}">
            <Border Background="{TemplateBinding Background}"
                    BorderBrush="{TemplateBinding BorderBrush}"
                    BorderThickness="{TemplateBinding BorderThickness}">
                <ContentPresenter Margin="{TemplateBinding Padding}"
                                    HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                    VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
            </Border>
        </ControlTemplate>
    </Setter.Value>
</Setter>