简体   繁体   English

C#中的路径:WPF

[英]Paths in c# : WPF

I am making a customize window for which I need to draw certain path in canvas, but all I have to do is make the path in c# instead of XAML, I have written paths in xaml but unable to convert them in c#.. Here is my paths 我正在制作一个自定义窗口,需要在画布上绘制某些路径,但是我要做的就是用c#而不是XAML生成路径,我已经在xaml中编写了路径,但是无法在c#中转换它们。我的路

 <Canvas xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Name="appbar_close" Clip="F1 M 0,0L 76,0L 76,76L 0,76L 0,0" Margin="1350,20,-252,302" >
                        <Path Width="10" Height="10" Canvas.Left="0" Canvas.Top="0" Stretch="Fill" Fill="#FF000000" Data="F1 M 26.9166,22.1667L 37.9999,33.25L 49.0832,22.1668L 53.8332,26.9168L 42.7499,38L 53.8332,49.0834L 49.0833,53.8334L 37.9999,42.75L 26.9166,53.8334L 22.1666,49.0833L 33.25,38L 22.1667,26.9167L 26.9166,22.1667 Z " MouseLeftButtonUp="mouseleftbuttonup" />
                    </Canvas>
                    <Canvas xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Name="appbar_minus" Clip="F1 M 0,0L 76,0L 76,76L 0,76L 0,0" Margin="1310,24,-211,302">
                        <Path Width="10" Height="3" Canvas.Left="0" Stretch="Fill" Fill="#FF000000" Data="F1 M 19,38L 57,38L 57,44L 19,44L 19,38 Z "/>
                    </Canvas>
                    <Canvas xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Name="appbar_app" Clip="F1 M 0,0L 76,0L 76,76L 0,76L 0,0" Margin="1330,19,-231,302">
                        <Path Width="8" Height="8" Canvas.Left="0" Canvas.Top="3" Stretch="Fill" Fill="#FF000000" Data="F1 M 18,23L 58,23L 58,53L 18,53L 18,23 Z M 54,31L 22,31L 22,49L 54,49L 54,31 Z "/>
                    </Canvas>

thanks in advance!! 提前致谢!!

The syntax for creating a Canvas and adding a Path to it in code-behind goes a little something like this: 创建Canvas并在背后的代码中添加路径的语法有点像这样:

var canvas = new Canvas
             {
                 Clip = Geometry.Parse("F1 M 0,0L 76,0L 76,76L 0,76L 0,0"),
                 Margin = new Thickness(1330, 19, -231, 302)
             };

var path = new Path
           {
               Width = 8,
               Height = 8,
               Fill = new SolidColorBrush(Colors.Black),
               Stretch = Stretch.Fill,
               Data = Geometry.Parse("F1 M 18,23L 58,23L 58,53L 18,53L 18,23 Z M 54,31L 22,31L 22,49L 54,49L 54,31 Z")
           };

canvas.Children.Add(path);
Canvas.SetTop(path, 3);
Canvas.SetLeft(path, 3);

Disclaimer: This was not tested. 免责声明:这未经测试。

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

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