WPF Transformations — Rotating and switching width/height?

南笙酒味 提交于 2019-12-12 17:29:52

问题


Basically, I have a FooControl (I did not set the Height/Width explicitly) added to a 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>

But, the problem now is that the FooControl fills up the entire row and when it's transformed it looks quite bizarre (because of it's height/width).


FooControl is a custom control. So do I do something with the ArrangeOverride or MeasureOverride? Or am I doing something wrong that can be fixed in XAML.

回答1:


1 - Use LayoutTransform
2 - Set HorizontalAlignment to Left or Right to prevent stretching

<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:


I'm not sure what you mean by 'bizarre', but I'd suggest to try and use LayoutTransform instead of RenderTransform - that's probably the issue.

Due note however that LayoutTransform is significantly slower than RenderTransform.




回答3:


Use LayoutTransform instead of RenderTransform.

http://patconroy.wordpress.com/2009/03/24/layouttransform-vs-rendertransform-in-wpf/

Simple :)



来源:https://stackoverflow.com/questions/5554701/wpf-transformations-rotating-and-switching-width-height

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!