WPF实现线条圆弧等几何曲线设计界面

WPF实现线条圆弧等几何曲线设计界面,效果及界面程序如下:WPF实现线条圆弧等几何曲线设计界面_第1张图片

<Window x:Class="GeometryDesignerDemo.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:GeometryDesignerDemo"
        mc:Ignorable="d"
        Title="MainWindow" ContentRendered="OnUiReady">
    <StackPanel Orientation="Horizontal" ClipToBounds="True" VerticalAlignment="Stretch">
        <Grid Width="200" VerticalAlignment="Stretch" Background="LightGray" Name="LeftPanel">
            <Grid.RowDefinitions>
                <RowDefinition Height="100" />
                <RowDefinition Height="*" />
                <RowDefinition Height="80" />
            Grid.RowDefinitions>
            <Border Grid.Row="0" BorderThickness="2" BorderBrush="Black" HorizontalAlignment="Stretch"
                    VerticalAlignment="Stretch" Background="LightYellow">
                <Canvas>
                    <Label Canvas.Left="0" Canvas.Top="5" FontStyle="Italic" FontWeight="Bold" FontSize="14">Step 1:Label>
                    <Label FontSize="12" Canvas.Left="10" Canvas.Top="25">Select GeometryLabel>
                    <ComboBox Name="GeometryTypeCB" SelectionChanged="OnGeometrySelectionChange" Canvas.Top="50"
                              Canvas.Left="12" MaxWidth="80" Width="80" SelectedIndex="0">
                        <ComboBoxItem>LineComboBoxItem>
                        <ComboBoxItem>EllipseComboBoxItem>
                        <ComboBoxItem>RectangleComboBoxItem>
                        <ComboBoxItem>ArcComboBoxItem>
                        <ComboBoxItem>BezierComboBoxItem>
                    ComboBox>
                Canvas>
            Border>
            <Border Grid.Row="1" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" BorderThickness="2"
                    BorderBrush="Black" Background="LightYellow">
                <StackPanel Orientation="Vertical" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
                            Name="ControlPointPane">
                    <Canvas Name="LinePane" Width="0" Height="0" ClipToBounds="True">
                        <Label FontSize="14" FontStyle="Italic" FontWeight="Bold" Canvas.Left="0">Step 2:Label>
                        <Label FontSize="12" FontStyle="Italic" FontWeight="Bold" Canvas.Left="55" Canvas.Top="3">Set Control pointsLabel>
                        <Label FontSize="12" FontWeight="Bold" Canvas.Left="5" Canvas.Top="47">StartPoint =Label>
                        <TextBox AcceptsTab="False" Name="LineStartPoint" Width="50" Canvas.Left="90" Canvas.Top="47" />
                        <Label FontSize="12" FontWeight="Bold" Canvas.Left="5" Canvas.Top="75" xml:space="preserve">EndPoint   =Label>
                        <TextBox AcceptsTab="False" Name="LineEndPoint" Width="50" Canvas.Left="90" Canvas.Top="75" />
                        <Label FontSize="14" FontWeight="Bold" Canvas.Left="89" Canvas.Top="110">OfLabel>
                        <Label FontSize="14" FontWeight="Bold" Canvas.Left="45" Canvas.Top="130">Line GeometryLabel>
                        <Button Canvas.Top="171" Canvas.Left="70" Width="55" Click="OnInsertGeometry">InsertButton>
                    Canvas>
                    <Canvas Name="EllipsePane" Width="0" Height="0" ClipToBounds="True">
                        <Label FontSize="14" FontStyle="Italic" FontWeight="Bold" Canvas.Left="0">Step 2:Label>
                        <Label FontSize="12" FontStyle="Italic" FontWeight="Bold" Canvas.Left="55" Canvas.Top="3">Set Control pointsLabel>
                        <Label FontSize="12" FontWeight="Bold" Canvas.Left="5" Canvas.Top="45" xml:space="preserve">Center     = Label>
                        <TextBox AcceptsTab="False" Name="EllipseCenterPoint" Width="50" Canvas.Left="90"
                                 Canvas.Top="45" />
                        <Label FontSize="12" FontWeight="Bold" Canvas.Left="5" Canvas.Top="75" xml:space="preserve">RadiusX   =Label>
                        <TextBox Name="EllipseRadiusX" Width="50" Canvas.Left="90" Canvas.Top="75" />
                        <Label FontSize="12" FontWeight="Bold" Canvas.Left="5" Canvas.Top="105" xml:space="preserve">RadiusY   =Label>
                        <TextBox Name="EllipseRadiusY" Width="50" Canvas.Left="90" Canvas.Top="105" />
                        <Label FontSize="14" FontWeight="Bold" Canvas.Left="89" Canvas.Top="140">OfLabel>
                        <Label FontSize="14" FontWeight="Bold" Canvas.Left="30" Canvas.Top="160">Ellipse GeometryLabel>
                        <Button Canvas.Top="201" Canvas.Left="70" Width="55" Click="OnInsertGeometry">InsertButton>
                    Canvas>
                    <Canvas Name="RectanglePane" Width="0" Height="0" ClipToBounds="True">
                        <Label FontSize="14" FontStyle="Italic" FontWeight="Bold" Canvas.Left="0">Step 2:Label>
                        <Label FontSize="12" FontStyle="Italic" FontWeight="Bold" Canvas.Left="55" Canvas.Top="3">Set Control pointsLabel>
                        <Label FontSize="12" FontWeight="Bold" Canvas.Left="5" Canvas.Top="45" xml:space="preserve">TopLeft    = Label>
                        <TextBox Name="RectangleTopLeftPoint" Width="50" Canvas.Left="90" Canvas.Top="45" />
                        <Label FontSize="12" FontWeight="Bold" Canvas.Left="5" Canvas.Top="75" xml:space="preserve">Width      =Label>
                        <TextBox Name="RectangleWidth" Width="50" Canvas.Left="90" Canvas.Top="75" />
                        <Label FontSize="12" FontWeight="Bold" Canvas.Left="5" Canvas.Top="105" xml:space="preserve">Height     =Label>
                        <TextBox Name="RectangleHeight" Width="50" Canvas.Left="90" Canvas.Top="105" />
                        <Label FontSize="12" FontWeight="Bold" Canvas.Left="5" Canvas.Top="135" xml:space="preserve">RadiusX  =Label>
                        <TextBox Name="RectangleRadiusX" Width="50" Canvas.Left="90" Canvas.Top="135">0TextBox>
                        <Label FontSize="12" FontWeight="Bold" Canvas.Left="5" Canvas.Top="165" xml:space="preserve">RadiusY  =Label>
                        <TextBox Name="RectangleRadiusY" Width="50" Canvas.Left="90" Canvas.Top="165">0TextBox>
                        <Label FontSize="14" FontWeight="Bold" Canvas.Left="89" Canvas.Top="200">OfLabel>
                        <Label FontSize="14" FontWeight="Bold" Canvas.Left="25" Canvas.Top="220">Rectangle GeometryLabel>
                        <Button Canvas.Top="261" Canvas.Left="70" Width="55" Click="OnInsertGeometry">InsertButton>
                    Canvas>
                    <Canvas Name="BezierPane" Width="0" Height="0" ClipToBounds="True">
                        <Label FontSize="14" FontStyle="Italic" FontWeight="Bold" Canvas.Left="0">Step 2:Label>
                        <Label FontSize="12" FontStyle="Italic" FontWeight="Bold" Canvas.Left="55" Canvas.Top="3">Set Control pointsLabel>
                        <Label FontSize="12" FontWeight="Bold" Canvas.Left="5" Canvas.Top="45" xml:space="preserve">StartPoint  = Label>
                        <TextBox Name="BezierStartPoint" Width="50" Canvas.Left="90" Canvas.Top="45" />
                        <Label FontSize="12" FontWeight="Bold" Canvas.Left="5" Canvas.Top="75" xml:space="preserve">Point1      =Label>
                        <TextBox Name="BezierPoint1" Width="50" Canvas.Left="90" Canvas.Top="75" />
                        <Label FontSize="12" FontWeight="Bold" Canvas.Left="5" Canvas.Top="105" xml:space="preserve">Point2     =Label>
                        <TextBox Name="BezierPoint2" Width="50" Canvas.Left="90" Canvas.Top="105" />
                        <Label FontSize="12" FontWeight="Bold" Canvas.Left="5" Canvas.Top="135" xml:space="preserve">Point3     =Label>
                        <TextBox Name="BezierPoint3" Width="50" Canvas.Left="90" Canvas.Top="135" />
                        <Label FontSize="14" FontWeight="Bold" Canvas.Left="89" Canvas.Top="175">OfLabel>
                        <Label FontSize="14" FontWeight="Bold" Canvas.Left="75" Canvas.Top="195">BezierLabel>
                        <Button Canvas.Top="221" Canvas.Left="70" Width="55" Click="OnInsertGeometry">InsertButton>
                    Canvas>
                    <Canvas Name="ArcPane" Width="0" Height="0" ClipToBounds="True">
                        <Label FontSize="14" FontStyle="Italic" FontWeight="Bold" Canvas.Left="0">Step 2:Label>
                        <Label FontSize="12" FontStyle="Italic" FontWeight="Bold" Canvas.Left="55" Canvas.Top="3">Set Control pointsLabel>
                        <Label FontSize="12" FontWeight="Bold" Canvas.Left="5" Canvas.Top="45" xml:space="preserve">StartPoint  = Label>
                        <TextBox Name="ArcStartPoint" Width="50" Canvas.Left="90" Canvas.Top="45" />
                        <Label FontSize="12" FontWeight="Bold" Canvas.Left="5" Canvas.Top="75" xml:space="preserve">Point       =Label>
                        <TextBox Name="ArcPoint" Width="50" Canvas.Left="90" Canvas.Top="75" />
                        <Label FontSize="12" FontWeight="Bold" Canvas.Left="5" Canvas.Top="105" xml:space="preserve">Size        =Label>
                        <TextBox Name="ArcSize" Width="50" Canvas.Left="90" Canvas.Top="105" />
                        <Label FontSize="12" FontWeight="Bold" Canvas.Left="5" Canvas.Top="135" xml:space="preserve">XRotation =Label>
                        <TextBox Name="ArcXRotation" Width="50" Canvas.Left="90" Canvas.Top="135" />
                        <Label FontSize="12" FontWeight="Bold" Canvas.Left="5" Canvas.Top="165" xml:space="preserve">LargeArc   =Label>
                        <ComboBox Name="ArcLargeArc" Width="60" Canvas.Left="90" Canvas.Top="165" SelectedIndex="0">
                            <ComboBoxItem>TRUEComboBoxItem>
                            <ComboBoxItem>FALSEComboBoxItem>
                        ComboBox>
                        <Label FontSize="12" FontWeight="Bold" Canvas.Left="5" Canvas.Top="195" xml:space="preserve">SweepArcDirection  =Label>
                        <ComboBox Name="ArcSweepArc" Width="60" Canvas.Left="90" Canvas.Top="195" SelectedIndex="0">
                            <ComboBoxItem>ClockwiseComboBoxItem>
                            <ComboBoxItem>CounterclockwiseComboBoxItem>
                        ComboBox>
                        <Label FontSize="14" FontWeight="Bold" Canvas.Left="89" Canvas.Top="235">OfLabel>
                        <Label FontSize="14" FontWeight="Bold" Canvas.Left="25" Canvas.Top="255">Arc GeometryLabel>
                        <Button Canvas.Top="296" Canvas.Left="70" Width="55" Click="OnInsertGeometry">InsertButton>
                    Canvas>

                StackPanel>
            Border>
            <Border Grid.Row="2" BorderThickness="2" BorderBrush="Black" Background="LightYellow"
                    HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                <StackPanel Orientation="Vertical" VerticalAlignment="Stretch">
                    <StackPanel Orientation="Horizontal">
                        <Label FontSize="14" FontStyle="Italic" FontWeight="Bold" Canvas.Left="0">Step 3:Label>
                        <Label FontSize="12" FontStyle="Italic" FontWeight="Bold" Canvas.Left="55" Canvas.Top="3">Generate xamlLabel>
                    StackPanel>
                    <StackPanel Height="10" />
                    <Button Name="ShowHideXAMLButton" Width="120" Click="OnShowHideXaml">
                        <Label FontSize="13" FontWeight="Bold">Show XAMLLabel>
                    Button>
                StackPanel>
            Border>
        Grid>
        <Canvas Width="1000" VerticalAlignment="Stretch" Name="DesignerPane" ClipToBounds="True">
            <Canvas Width="1000" Height="1000" Canvas.Left="0" Canvas.Top="0">
                <Canvas.Background>
                    <VisualBrush x:Name="LogoBrush"
                                 TileMode="Tile" Viewport="0,0,0.3,0.1">
                        <VisualBrush.Visual>
                            <Border Background="Transparent">
                                <TextBlock
                                    x:Name="geoText"
                                    Text="Geometry Designer"
                                    FontFamily="Comic Sans MS" FontSize="14pt" Foreground="LightGray"
                                    Margin="5,5,10,5" />
                            Border>
                        VisualBrush.Visual>
                    VisualBrush>
                Canvas.Background>

                <Rectangle
                    Width="{Binding ElementName=DrawingPane, Path=ActualWidth}"
                    Height="{Binding ElementName=DrawingPane, Path=ActualHeight}">
                    <Rectangle.Fill>
                        <DrawingBrush x:Name="GridBrush"
                                      Viewport="0,0,10,10" ViewportUnits="Absolute" TileMode="Tile"
                                      Opacity="0">
                            <DrawingBrush.Drawing>
                                <DrawingGroup>
                                    <GeometryDrawing Brush="#CCCCFF">
                                        <GeometryDrawing.Geometry>
                                            <RectangleGeometry Rect="0,0 10,1" />
                                        GeometryDrawing.Geometry>
                                    GeometryDrawing>
                                    <GeometryDrawing Brush="#CCCCFF">
                                        <GeometryDrawing.Geometry>
                                            <RectangleGeometry Rect="0,0 1,10" />
                                        GeometryDrawing.Geometry>
                                    GeometryDrawing>
                                DrawingGroup>
                            DrawingBrush.Drawing>
                        DrawingBrush>
                    Rectangle.Fill>
                Rectangle>

                <Canvas Width="1000" Height="1000" Canvas.Left="0" Canvas.Top="0" Name="DrawingPane" />

                <Canvas.Triggers>
                    <EventTrigger RoutedEvent="Canvas.Loaded">
                        <BeginStoryboard>
                            <Storyboard>
                                <DoubleAnimation
                                    Storyboard.TargetName="LogoBrush"
                                    Storyboard.TargetProperty="Opacity"
                                    BeginTime="0:0:2"
                                    Duration="0:0:5"
                                    From="1"
                                    To="0" />
                                <DoubleAnimation
                                    Storyboard.TargetName="GridBrush"
                                    Storyboard.TargetProperty="Opacity"
                                    BeginTime="0:0:5"
                                    Duration="0:0:5"
                                    From="0"
                                    To="1" />
                            Storyboard>
                        BeginStoryboard>
                    EventTrigger>
                Canvas.Triggers>
            Canvas>
            <DockPanel Name="XAMLPane" Width="0" Height="0">
                <TextBox AcceptsTab="False" VerticalAlignment="Stretch" AcceptsReturn="True" Background="LightYellow"
                         TextWrapping="Wrap" />
            DockPanel>
        Canvas>
    StackPanel>
Window>

你可能感兴趣的:(WPF软件开发,wpf)