c# - WPF 更改边距将其他元素向下推

标签 c# wpf xaml margin

首先,抱歉我的英语不好。

我想让按钮“弹出”?当我将鼠标悬停在它们上面时在我的应用程序中。

这是我想出的:

 <Style x:Key="SelectButton" TargetType="Button" BasedOn="{StaticResource {x:Type Button}}">
        <Style.Triggers>
            <Trigger Property="IsMouseOver" Value="False">
                <Setter Property="Content">
                    <Setter.Value>
                        <Image Source="\directory"/>
                    </Setter.Value>
                </Setter>
                <Setter Property="Margin">
                    <Setter.Value>
                        <Thickness Bottom="10" Right="10" Top="10" Left="10"/>
                    </Setter.Value>
                </Setter>
            </Trigger>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter Property="Content">
                    <Setter.Value>
                        <Image Source ="\directory"/>
                    </Setter.Value>
                </Setter>
                <Setter Property="Margin">
                    <Setter.Value>
                        <Thickness Bottom="0" Right="0" Top="0" Left="0"/>
                    </Setter.Value>
                </Setter>
            </Trigger>
        </Style.Triggers>
    </Style>

你可以在这里看到编译后的样子:

enter image description here

问题是,每当我更改按钮的边距时,它都会将应用程序的所有其他元素向下推。老实说,我没有想法。

提前致谢。

最佳答案

嗯,您正在调整按钮的大小,这会导致此行为。这完全是预料之中的。

幸运的是,您真正想做的是申请 RenderTransform .它们不影响布局。从文档中,

A render transform does not regenerate layout size or render size information. Render transforms are typically intended for animating or applying a temporary effect to an element. For example, the element might zoom when focused or moused over, or might jitter on load to draw the eye to that part of the user interface (UI).

您需要使用 ScaleTransform .变形很有趣。在您使用它后不久就会意识到您可以为它们制作动画,然后您就会为它们制作动画。

关于c# - WPF 更改边距将其他元素向下推,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48713514/

相关文章:

c# - 将字节数组与掩码进行比较

.net - 在 WPF 中并排制作标签和文本框的预期方法是什么?

wpf - 绑定(bind)到 DataGridColumnHeader.Command

c# - XAML 设计器中的 "Method not found"错误

c# - WPF MouseDown 事件不会在控件中的任何地方触发

c# - 遍历变量名

c# - 如何在 Windows Azure 上设置 Websocket 连接?

c# - 捕获 TableLayoutPanel 特定区域的图像

c# - 如何确定 Assembly.LoadFrom 真的加载了一个 DLL 文件?

c# - 调用 Application.Shutdown() 后,使用 ShowDialog 显示窗口不起作用