简体   繁体   English

WPF SkewTransform

[英]WPF SkewTransform

I want to create something like this in WPF 我想在WPF中创建类似的东西

在此处输入图片说明

To do that I have written these lines: 为此,我写了以下几行:

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition></ColumnDefinition>
        <ColumnDefinition></ColumnDefinition>
    </Grid.ColumnDefinitions>
    <Border Grid.Column="0"  BorderThickness="10" BorderBrush="Black" Margin="0,33,0,114"   >
        <Border.RenderTransform>
            <TransformGroup>
                <ScaleTransform/>
                <SkewTransform AngleY="-10"/>
                <RotateTransform/>
                <TranslateTransform Y="71.691"/>
            </TransformGroup>
        </Border.RenderTransform>
        <Border  Background="BurlyWood" />
    </Border>
    <Border Grid.Column="1"  BorderThickness="10" BorderBrush="Black" RenderTransformOrigin="0.5,0.5" Margin="0,39,0,107"  >
        <Border.RenderTransform>
            <TransformGroup>
                <ScaleTransform/>
                <SkewTransform AngleY="10"/>
                <RotateTransform/>
                <TranslateTransform Y="41.82"/>
            </TransformGroup>
        </Border.RenderTransform>
        <Border  Background="BurlyWood" />
    </Border>
</Grid>

But the problem is when I resize the window, the left panel goes upper than the right panel and vise-versa. 但是问题是当我调整窗口大小时,左面板比右面板高,反之亦然。 like this: 像这样: 在此处输入图片说明

How can I make them stick to each other? 我怎样才能使它们彼此粘合?

I believe you should use the LayoutTransform other than the RenderTransform. 我相信您应该使用RenderTransform以外的LayoutTransform。

The skewed shapes should fit actually the available area, and the LayoutTransform does that. 倾斜的形状应实际适合可用区域,而LayoutTransform会做到这一点。

UPDATE: the below XAML works for me: 更新:以下XAML对我有用:

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition></ColumnDefinition>
        <ColumnDefinition></ColumnDefinition>
    </Grid.ColumnDefinitions>
    <Border Grid.Column="0" BorderThickness="10" BorderBrush="Black" 
            Background="BurlyWood" Margin="0,50"
            >
        <Border.LayoutTransform>
            <TransformGroup>
                <SkewTransform AngleY="10"/>
                <ScaleTransform ScaleX="-1" />
                <RotateTransform/>
            </TransformGroup>
        </Border.LayoutTransform>
        <Border>
            <Border.LayoutTransform>
                <ScaleTransform ScaleX="-1" />
            </Border.LayoutTransform>
            <TextBlock TextWrapping="Wrap" Margin="10,20">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</TextBlock>
        </Border>
    </Border>
    <Border Grid.Column="1" BorderThickness="10" BorderBrush="Black"
            Background="BurlyWood"  Margin="0,50"
            >
        <Border.LayoutTransform>
            <TransformGroup>
                <ScaleTransform/>
                <SkewTransform AngleY="10"/>
                <RotateTransform/>
            </TransformGroup>
        </Border.LayoutTransform>
        <TextBlock TextWrapping="Wrap" Margin="10,20">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</TextBlock>
    </Border>
</Grid>

UPDATE 2: added the margin. 更新2:增加了边距。

UPDATE 3: patch for the correct scaling of the content. 更新3:修补内容的正确缩放。

在此处输入图片说明

Make the vertical margins the same thickness for each Border . 使每个Border的垂直边距具有相同的厚度。 It is probably better to apply the margins to the parent Grid and delete the Border margins completely. 将边距应用于父Grid并完全删除Border边距可能更好。

The Top margin component is different for each Border . 每个Border边距部分不同。

http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.margin%28v=vs.110%29.aspx http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.margin%28v=vs.110%29.aspx

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

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