当鼠标悬停时按钮增长 8 像素 WPF XAML
我正在处理一个相当令人沮丧的错误。我的最终目标是拥有一个图像,该图像在 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" />
这就是正在发生的事情:
感谢您的任何建议。
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:
Thanks for any suggestions.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
前几天我也遇到了这个问题,可能其中一张图像是标准的 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.