WPF 实现元素上下左右对称

<UserControl x:Class="CMApplication1.Views.PhotoEditorView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             mc:Ignorable="d"
             d:DesignHeight="300" d:DesignWidth="300">
    <UserControl.Resources>
        <VisualBrush x:Key="myVisual">
            <VisualBrush.Visual>
                <Grid>
                    <Rectangle Height="200" Width="200" Fill="Red" HorizontalAlignment="Right"  VerticalAlignment="Top" ></Rectangle>
                </Grid>
            </VisualBrush.Visual>
        </VisualBrush>
    </UserControl.Resources>
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition />
        </Grid.RowDefinitions>
           
        <Grid >
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <Image Grid.Column="1"  VerticalAlignment="Center" HorizontalAlignment="Center" x:Name="imgVisual1" Source="/images/DD.jpg" Stretch="Fill">
                <!--<Image.Clip>
                    <EllipseGeometry RadiusX="100" RadiusY="75" Center="200,175"/>
                </Image.Clip>-->
            </Image>
            <Rectangle VerticalAlignment="Center" HorizontalAlignment="Center" Width="{Binding ActualWidth,ElementName=imgVisual1}" Height="{Binding ActualHeight,ElementName=imgVisual1}">
                <Rectangle.Fill>
                    <VisualBrush Visual="{Binding ElementName=imgVisual1}">
                        <VisualBrush.RelativeTransform>
                            <ScaleTransform ScaleX="-1" ScaleY="1" CenterX="0.5" CenterY="0.5"></ScaleTransform>
                        </VisualBrush.RelativeTransform>
                    </VisualBrush>
                </Rectangle.Fill>
            </Rectangle>
        </Grid>
        <Grid Grid.Column="1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <Image VerticalAlignment="Center" HorizontalAlignment="Center" x:Name="imgVisual2" Source="/images/EE.jpg" Stretch="Fill">
                  
            </Image>
            <Rectangle Grid.Column="1"  VerticalAlignment="Center" HorizontalAlignment="Center" Width="{Binding ActualWidth,ElementName=imgVisual2}" Height="{Binding ActualHeight,ElementName=imgVisual2}">
                <Rectangle.Fill>
                    <VisualBrush Visual="{Binding ElementName=imgVisual2}">
                        <VisualBrush.RelativeTransform>
                            <ScaleTransform ScaleX="-1" ScaleY="1" CenterX="0.5" CenterY="0.5"></ScaleTransform>
                        </VisualBrush.RelativeTransform>
                    </VisualBrush>
                </Rectangle.Fill>
            </Rectangle>
        </Grid>
        <Grid Visibility="Collapsed">
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <Image x:Name="imgVisual5" Source="/images/EE.jpg" Stretch="Fill">
                <Image.Clip>
                    <EllipseGeometry RadiusX="100" RadiusY="75" Center="100,75"/>
                </Image.Clip>
            </Image>
            <!--<Rectangle Grid.Column="1" Width="{Binding ActualWidth,ElementName=imgVisual5}" Height="{Binding ActualHeight,ElementName=imgVisual5}">-->
            <Rectangle Grid.Column="1" Width="200" Height="150">
                <Rectangle.Fill>
                    <VisualBrush Visual="{Binding ElementName=imgVisual5}">
                        <VisualBrush.RelativeTransform>
                            <ScaleTransform ScaleX="-1" ScaleY="1" CenterX="0.5" CenterY="0.5"></ScaleTransform>
                        </VisualBrush.RelativeTransform>
                    </VisualBrush>
                </Rectangle.Fill>
                <!--<Rectangle.Clip>
                    <EllipseGeometry x:Name="yy" RadiusX="100" RadiusY="75" Center="100,75"/>
                </Rectangle.Clip>-->
            </Rectangle>
        </Grid>
        <!--上下对称-->
        <Grid Grid.Row="1">
            <Grid.RowDefinitions>
                <RowDefinition></RowDefinition>
                <RowDefinition></RowDefinition>
            </Grid.RowDefinitions>
            <Image Grid.Row="1" x:Name="imgVisual3" Source="/images/EE.jpg" Stretch="Fill"></Image>
            <Rectangle Width="{Binding ActualWidth,ElementName=imgVisual3}" Height="{Binding ActualHeight,ElementName=imgVisual3}">
                <Rectangle.Fill>
                    <VisualBrush Visual="{Binding ElementName=imgVisual3}">
                        <VisualBrush.RelativeTransform>
                            <ScaleTransform ScaleX="1" ScaleY="-1" CenterX="0.5" CenterY="0.5"></ScaleTransform>
                        </VisualBrush.RelativeTransform>
                    </VisualBrush>
                </Rectangle.Fill>
            </Rectangle>
        </Grid>
        <Grid Grid.Column="1" Grid.Row="1">
            <Grid.RowDefinitions>
                <RowDefinition></RowDefinition>
                <RowDefinition></RowDefinition>
            </Grid.RowDefinitions>
            <Image x:Name="imgVisual4" Source="/images/DD.jpg" Stretch="Fill"></Image>
            <Rectangle Grid.Row="1" Width="{Binding ActualWidth,ElementName=imgVisual4}" Height="{Binding ActualHeight,ElementName=imgVisual4}">
                <Rectangle.Fill>
                    <VisualBrush Visual="{Binding ElementName=imgVisual4}">
                        <VisualBrush.RelativeTransform>
                            <ScaleTransform ScaleX="1" ScaleY="-1" CenterX="0.5" CenterY="0.5"></ScaleTransform>
                        </VisualBrush.RelativeTransform>
                    </VisualBrush>
                </Rectangle.Fill>
            </Rectangle>
        </Grid>
        <!--备份-->
        <!--<Grid >
            <Grid.RowDefinitions>
                <RowDefinition></RowDefinition>
                <RowDefinition></RowDefinition>
            </Grid.RowDefinitions>
            <Image x:Name="imgVisual" Source="/images/EE.jpg" Stretch="Fill"></Image>
            <Rectangle Grid.Row="1" Width="{Binding ActualWidth,ElementName=imgVisual}" Height="{Binding ActualHeight,ElementName=imgVisual}">
                <Rectangle.Fill>
                    <VisualBrush Visual="{Binding ElementName=imgVisual}">
                        <VisualBrush.RelativeTransform>
                            <ScaleTransform ScaleX="1" ScaleY="-1" CenterX="0.5" CenterY="0.5"></ScaleTransform>
                        </VisualBrush.RelativeTransform>
                    </VisualBrush>
                </Rectangle.Fill>
                <Rectangle.OpacityMask>
                    <LinearGradientBrush StartPoint="0,0" EndPoint="0,0.5">
                        <GradientStop Offset="0" Color="Red"></GradientStop>
                        <GradientStop Offset="0.5" Color="Blue"></GradientStop>
                        <GradientStop Offset="1" Color="Transparent"></GradientStop>
                    </LinearGradientBrush>
                </Rectangle.OpacityMask>
            </Rectangle>
        </Grid>-->
    </Grid>
</UserControl>


知识共享许可协议
《WPF 实现元素上下左右对称》常伟华 创作。
采用 知识共享 署名-相同方式共享 3.0 中国大陆 许可协议进行许可。
相邻依据:发表时间
  • 多说评论
  • 签名
  • 新浪微博
  • 默认评论
  • Tab Header 5

0 条评论 / 点击此处发表评论

Tab Content 5

开发技术


开发平台和工具

sitemap     167.60ms