本文介绍了WPF转换-旋转和切换宽度/高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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>

但是,现在的问题是FooControl填满了整个行,​​并且在对其进行转换时,它看起来非常奇怪(因为它的高度/宽度).


FooControl是一个自定义控件.那我可以用ArrangeOverride或MeasureOverride做什么吗?还是我做错了一些可以在XAML中修复的问题.

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-使用LayoutTransform
2-将HorizontalAlignment设置为向左或向右以防止拉伸

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>

这篇关于WPF转换-旋转和切换宽度/高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-11 06:53