【问题标题】:WPF Transformations -- Rotating and switching width/height?WPF 转换——旋转和切换宽度/高度?
【发布时间】:2011-04-05 15:51:52
【问题描述】:

基本上,我将FooControl(我确实没有明确设置了高度/宽度)添加到Grid

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition />
        <RowDefinition />
    </Grid.RowDefinitions>
    <FooControl x:Name="HWFoo" Content="HelloWorld" Grid.Row="0">
        <FooControl.RenderTransform>
            <TransformGroup>
                <RotateTransform Angle="270" />
                <TranslateTransform Y="{Binding ActualWidth, ElementName=HWFoo}" />
            </TransformGroup>
        </FooControl.RenderTransform>
    </FooControl>
</Grid>

但是,现在的问题是 FooControl 填满了整行,当它被转换时,它看起来很奇怪(因为它的高度/宽度)。


FooControl 是一个自定义控件。那么我应该对 ArrangeOverride 或 MeasureOverride 做些什么吗?或者我做错了什么可以在 XAML 中修复。

【问题讨论】:

    标签: wpf custom-controls rotatetransform rendertransform


    【解决方案1】:

    1 - 使用 LayoutTransform
    2 - 将HorizontalAlignment 设置为向左或向右以防止拉伸

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition />
        </Grid.RowDefinitions>
        <FooControl x:Name="HWFoo" Content="HelloWorld" Grid.Row="0" HorizontalAlignment="Left">
            <FooControl.LayoutTransform>
                <TransformGroup>
                    <RotateTransform Angle="270" />
                    <TranslateTransform Y="{Binding ActualWidth, ElementName=HWFoo}" />
                </TransformGroup>
            </FooControl.LayoutTransform>
        </FooControl>
    </Grid>
    

    【讨论】:

      【解决方案2】:

      我不确定你所说的“奇怪”是什么意思,但我建议尝试使用 LayoutTransform 而不是 RenderTransform - 这可能是问题所在。

      但请注意,LayoutTransform 比 RenderTransform 慢得多。

      【讨论】:

        【解决方案3】:
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-06-12
        • 1970-01-01
        • 2018-05-06
        • 2014-12-31
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多