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

WPF实现线条圆弧等几何曲线设计界面,效果及界面程序如下:在这里插入图片描述

<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 Geometry</Label>
                    <ComboBox Name="GeometryTypeCB" SelectionChanged="OnGeometrySelectionChange" Canvas.Top="50"
                              Canvas.Left="12" MaxWidth="80" Width="80" SelectedIndex="0">
                        <ComboBoxItem>Line</ComboBoxItem>
                        <ComboBoxItem>Ellipse</ComboBoxItem>
                        <ComboBoxItem>Rectangle</ComboBoxItem>
                        <ComboBoxItem>Arc</ComboBoxItem>
                        <ComboBoxItem>Bezier</ComboBoxItem>
                    </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 points</Label>
                        <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">Of</Label>
                        <Label FontSize="14" FontWeight="Bold" Canvas.Left="45" Canvas.Top="130">Line Geometry</Label>
                        <Button Canvas.Top="171" Canvas.Left="70" Width="55" Click="OnInsertGeometry">Insert</Button>
                    </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 points</Label>
                        <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">Of</Label>
                        <Label FontSize="14" FontWeight="Bold" Canvas.Left="30" Canvas.Top="160">Ellipse Geometry</Label>
                        <Button Canvas.Top="201" Canvas.Left="70" Width="55" Click="OnInsertGeometry">Insert</Button>
                    </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 points</Label>
                        <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">0</TextBox>
                        <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">0</TextBox>
                        <Label FontSize="14" FontWeight="Bold" Canvas.Left="89" Canvas.Top="200">Of</Label>
                        <Label FontSize="14" FontWeight="Bold" Canvas.Left="25" Canvas.Top="220">Rectangle Geometry</Label>
                        <Button Canvas.Top="261" Canvas.Left="70" Width="55" Click="OnInsertGeometry">Insert</Button>
                    </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 points</Label>
                        <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">Of</Label>
                        <Label FontSize="14" FontWeight="Bold" Canvas.Left="75" Canvas.Top="195">Bezier</Label>
                        <Button Canvas.Top="221" Canvas.Left="70" Width="55" Click="OnInsertGeometry">Insert</Button>
                    </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 points</Label>
                        <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>TRUE</ComboBoxItem>
                            <ComboBoxItem>FALSE</ComboBoxItem>
                        </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>Clockwise</ComboBoxItem>
                            <ComboBoxItem>Counterclockwise</ComboBoxItem>
                        </ComboBox>
                        <Label FontSize="14" FontWeight="Bold" Canvas.Left="89" Canvas.Top="235">Of</Label>
                        <Label FontSize="14" FontWeight="Bold" Canvas.Left="25" Canvas.Top="255">Arc Geometry</Label>
                        <Button Canvas.Top="296" Canvas.Left="70" Width="55" Click="OnInsertGeometry">Insert</Button>
                    </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 xaml</Label>
                    </StackPanel>
                    <StackPanel Height="10" />
                    <Button Name="ShowHideXAMLButton" Width="120" Click="OnShowHideXaml">
                        <Label FontSize="13" FontWeight="Bold">Show XAML</Label>
                    </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>
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
### 回答1: 在WPF中,可以通过使用不同的界面元素和绑定技术来实现上一步和下一步界面切换。 首先,我们可以使用StackPanel或Grid等布局容器来承载不同的页面内容。通过在容器中添加多个子元素,每个子元素对应一个页面。然后,我们可以通过调整页面的可见性来实现页面的切换效果。例如,设置当前页面可见,同时将其他页面隐藏。 其次,可以使用命令和绑定技术来实现上一步和下一步按钮的功能。我们可以为每个按钮创建一个命令,并将命令绑定到按钮的Click事件。然后,我们可以在命令的执行方法中处理页面切换的逻辑。例如,当点击上一步按钮时,我们可以将当前页面的索引减1,并更新页面的可见性。当点击下一步按钮时,我们可以将当前页面的索引加1,并更新页面的可见性。 此外,我们还可以使用数据绑定来实现页面之间的数据传递。例如,我们可以在ViewModel中定义一个当前页面的属性,并在页面切换时更新该属性的值。然后,我们可以利用数据绑定机制将该属性绑定到页面中的控件上,以便在不同页面之间共享数据。 综上所述,通过使用布局容器、可见性调整、命令和绑定技术,我们可以实现WPF中的上一步和下一步界面切换功能。这样,用户就可以轻松地在不同的页面之间进行切换,并且可以实现数据的传递和共享。 ### 回答2: WPF (Windows Presentation Foundation) 是一种用于创建Windows应用程序界面的框架。要实现上一步和下一步界面切换,可以按照以下步骤进行操作: 1. 创建多个界面:首先,需要创建多个用户界面,每个界面代表一个步骤。可以使用XAML语言来定义界面的布局和外观,同时也可以通过编写C#代码来处理逻辑。 2. 导航控件:在WPF中,可以使用一些导航控件来实现界面之间的切换。常用的导航控件有Frame和Page。可以在主界面中放置一个Frame控件,然后在该Frame控件中加载不同的Page,每个Page对应一个步骤的界面。 3. 上一步和下一步按钮:可以在每个步骤的界面上添加上一步和下一步按钮,通过点击按钮来切换界面。在点击上一步按钮时,可以使用导航控件的GoBack()方法来返回上一个界面;在点击下一步按钮时,可以使用导航控件的Navigate()方法来跳转到下一个界面。 4. 界面数据传递:如果需要在不同界面之间传递数据,可以使用WPF提供的一些机制,例如使用共享的ViewModel来保存数据,或者通过事件来传递数据。 5. 界面导航逻辑:可以根据实际需求在每个界面的按钮事件中编写界面导航的逻辑。例如,可以在点击下一步按钮时进行一些数据验证,如果验证通过则跳转到下一个界面,否则给出提示信息。 总的来说,WPF通过导航控件和事件机制,可以很方便地实现上一步和下一步界面的切换。根据实际需求,可以进行适当的界面设计和数据传递,以提供良好的用户体验。 ### 回答3: WPF(Windows Presentation Foundation)是微软开发的一个用于构建Windows应用程序的UI框架。在WPF实现上一步和下一步界面切换可以通过以下步骤: 1. 首先,在XAML文件中创建两个或多个不同的界面,每个界面都使用一个Grid或者其他容器作为根元素。为了方便切换,可以给每个界面起一个独立的名字。 2. 创建一个主页面,该页面包含两个按钮,一个是“上一步”按钮,一个是“下一步”按钮。这两个按钮可以绑定到相应的事件处理方法。 3. 在代码中,需要创建事件处理方法来响应按钮的点击事件。在“上一步”按钮的事件处理方法中,使用VisualStateManager.GoToState方法来切换到上一个界面,通过设置要切换页面的Visibility属性来显示或隐藏相应的界面。在“下一步”按钮的事件处理方法中,同样使用VisualStateManager.GoToState方法来切换到下一个界面。 4. 在XAML文件中,通过VisualStateGroup、VisualState和Storyboard等元素来定义不同的界面状态,并在代码中使用VisualStateManager.GoToElementState来切换到相应的状态。 5. 最后,在主页面的Loaded事件中设置默认显示的界面,可以使用VisualStateManager.GoToState或者VisualStateManager.GoToElementState方法来切换到默认界面。 通过以上步骤,就可以在WPF实现上一步和下一步界面切换。关键是利用WPF的可视状态管理器(Visual State Manager)来定义界面状态,并在代码中切换到不同的状态,从而实现页面的切换效果。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

向着光-

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值