WPF样式触发器 [英] WPF Style Trigger

查看:99
本文介绍了WPF样式触发器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在样式触发器中更改了文本的FontSize,这也会导致包含文本的控件也重新调整大小。如何更改字号而不影响父级的尺寸?

I change the FontSize of Text in a Style trigger, this causes the Control containing the text to resize as well. How can I change the Fontsize without affecting the parent's size?

推荐答案

将元素与其父级布局隔离的一个不错的技巧是将元素放置在画布中

A nice trick to isolate an element from its parent layout wise is to place the element in a Canvas

在下面的标记中,元素有两个副本
第一个是隐藏的并确定控件的大小
第二个是可见的但包裹在Canvas中,因此

In the markup below there are two copies of your element The first is hidden and establishes the size of your control The second is visible but wrapped in a Canvas so its layout size does not affect the parent.

<Parent>
  <Grid>
    <Element Visibility="Hidden"/>
    <Canvas>
      <Element />
    </Canvas>
  <Grid>
</Parent>

这篇关于WPF样式触发器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆