3

例如,为什么我应该使用 ScaleX="2" 而不是控件宽度的两倍?

<Button Width = "100" Content="Button1"/>


<Button Width = "50" Content="Button2">
   <Button.RenderTransform>
      <ScaleTransform ScaleX="2" />
   </Button.RenderTransform>
</Button>

两个按钮看起来完全一样,所以再一次,什么比例适合

4

3 回答 3

3

Your concept of "exactly the same" seems to be different from mine.

截屏

您指定的大小WidthHeight影响控件在布局中占用的空间,这意味着控件可能会占用更多或更少的空间,但字体大小将保持不变。这RenderTransform是在此之上的操作,不再涉及布局,因此可能会扭曲控件。

渲染转换不会重新生成布局大小或渲染大小信息。渲染变换通常用于为元素设置动画或应用临时效果。例如,元素可能在聚焦或鼠标悬停时缩放,或者在加载时可能会抖动以将注意力吸引到用户界面 (UI) 的该部分。


另请参阅该LayoutTransform属性,它确实会影响布局但仍会扭曲控件。

于 2011-07-15T00:41:57.887 回答
2

当您无法缩放控件的某些部分时,它很有用。考虑 DatePicker 控件。默认实现的下拉日历对于我的用户来说太小了,因此我将这个 XAML 片段引入到我的 App.xaml 文件中:

<Style TargetType="w:DatePicker">
    <Setter Property="CalendarStyle">
        <Setter.Value>
            <Style TargetType="w:Calendar">
                <Setter Property="LayoutTransform">
                    <Setter.Value>
                        <ScaleTransform ScaleX="1.5" ScaleY="1.5" />
                    </Setter.Value>
                </Setter>
            </Style>
        </Setter.Value>
    </Setter>
</Style>

现在日历是原来的 1.5 倍,我的用户很高兴。没有我可以直接设置的“CalendarWidth”或“CalendarHeight”属性,所以ScaleTransform节省了一天。

于 2011-07-15T00:26:49.133 回答
2

What if it was more complicated than a Button with a Width? What if you had a complex Path/Geometry, or maybe even a group of controls? You wouldn't want to go and manually change everything. What if you had a custom control, where you wanted to give one instance the size 100x100, and another instance 150x150? What if you were implementing zoom functionality (think google maps)?

In short, for your specific example, it doesn't provide much use. But there are many other cases where it does.

于 2011-07-15T00:40:59.973 回答