当鼠标悬停时按钮增长 8 像素 WPF XAML

发布于 2024-09-13 17:40:12 字数 1588 浏览 2 评论 0原文

我正在处理一个相当令人沮丧的错误。我的最终目标是拥有一个图像,该图像在 IsMouseOver 上发光,并且可以单击来调用事件。这看起来太复杂了,但我发现的另一种选择是创建自定义用户控件,这甚至更加过度。这就是我到目前为止所做的:

<Style x:Key="DelButton" TargetType="Button">
        <Setter Property="Padding" Value="0" />
        <Setter Property="Background" Value="Red" />
        <Setter Property="BorderBrush" Value="Transparent" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Button">
                    <Image Source="/HaskList;component/Images/Del24.png" Stretch="None"/>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="Button">
                            <Image Source="/HaskList;component/Images/Del24h.png" Stretch="None"/>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Trigger>
        </Style.Triggers>
    </Style>

我的按钮定义为:

<Button HorizontalAlignment="Right" Margin="0,28,6,0" Name="delButton" VerticalAlignment="Top" Style="{DynamicResource DelButton}" Click="delButton_Click" />

这就是正在发生的事情:

alt text

感谢您的任何建议。

I'm dealing with a rather frustrating bug. My ultimate goal is to have an image, which glows on IsMouseOver, and can be clicked to call an event. This seems all too complicated, but the other alternative I found was creating a custom user control, which is even more excessive. This is what I've done so far:

<Style x:Key="DelButton" TargetType="Button">
        <Setter Property="Padding" Value="0" />
        <Setter Property="Background" Value="Red" />
        <Setter Property="BorderBrush" Value="Transparent" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Button">
                    <Image Source="/HaskList;component/Images/Del24.png" Stretch="None"/>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="Button">
                            <Image Source="/HaskList;component/Images/Del24h.png" Stretch="None"/>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Trigger>
        </Style.Triggers>
    </Style>

My button is defined as:

<Button HorizontalAlignment="Right" Margin="0,28,6,0" Name="delButton" VerticalAlignment="Top" Style="{DynamicResource DelButton}" Click="delButton_Click" />

This is what's happening:

alt text

Thanks for any suggestions.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凝望流年 2024-09-20 17:40:12

前几天我也遇到了这个问题,可能其中一张图像是标准的 96dpi,而另一张图像是其他的。我有一张图像的分辨率为 78 dpi 或其他,这就是为什么它的尺寸变得奇怪。

i ran into this the other day too, and it might be that one of the images is a standard 96dpi, and the other was something else. I had one image that somehow was 78 dpi or something else, and thats why it was getting strange sizing.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文