简体   繁体   English

ScaleTransform 有什么用?

[英]What is ScaleTransform good for?

why I should use ScaleX="2" for example instead of double the width of my control??例如,为什么我应该使用 ScaleX="2" 而不是控件宽度的两倍?

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


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

both buttons look exactly the same so again, what scale is good for两个按钮看起来完全一样,所以再一次,什么比例适合

Your concept of "exactly the same" seems to be different from mine.您的“完全相同”的概念似乎与我的不同。

截屏

The sizes you specify with Width and Height affect how much space the control takes up in the layout, this means that the control may take more or less space but the font size will stay the same for example.您使用WidthHeight指定的大小会影响控件在布局中占用的空间,这意味着控件可能占用更多或更少的空间,但字体大小将保持不变。 The RenderTransform is a manipulation on top of this which no longer concerns the layout and hence may distort the control. 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).例如,元素可能在聚焦或鼠标悬停时缩放,或者在加载时可能会抖动以将注意力吸引到用户界面 (UI) 的该部分。


See also the LayoutTransform property, which does affect layout but still distorts the control.另请参阅LayoutTransform属性,它确实会影响布局但仍会扭曲控件。

It's useful when you don't have the ability to scale some parts of a control.当您无法缩放控件的某些部分时,它很有用。 Consider the DatePicker control.考虑 DatePicker 控件。 The default implementation has a drop-down calendar that was too small for my users' liking, so I introduced this snippet of XAML into my App.xaml file:默认实现的下拉日历对我的用户来说太小了,所以我将这个 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>

Now the calendar is 1.5 times as big, and my users are happy.现在日历是原来的 1.5 倍,我的用户很高兴。 There is no "CalendarWidth" or "CalendarHeight" property that I can set directly, so the ScaleTransform saved the day.没有我可以直接设置的“CalendarWidth”或“CalendarHeight”属性,因此ScaleTransform节省了时间。

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.您不想 go 并手动更改所有内容。 What if you had a custom control, where you wanted to give one instance the size 100x100, and another instance 150x150?如果你有一个自定义控件,你想给一个实例大小为 100x100,另一个实例为 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.但还有许多其他情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM