WPF里如何动态调整控件位置

控件的位置往往是需要动态调整的,那么在WPF里如何设置呢?

我们需要用到控件的Margin属性。

首先的大前提是我们要把控件的对齐方式设置好,比如向上向左对齐或者向下向右对齐,否则相对的另一方向的参数就没有作用了。

然后在C#代码里用 Thickness来调整,这里我就用常量举例了:

button1.Margin = new Thickness(10,10,0,0);

就这么简单,希望有帮助。

You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>