【问题标题】:Paths in c# : WPFc# 中的路径:WPF
【发布时间】:2014-08-06 04:38:36
【问题描述】:

我正在创建一个自定义窗口,我需要在画布中绘制某些路径,但我所要做的就是在 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>

提前致谢!!

【问题讨论】:

    标签: c# .net wpf visual-studio-2010 xaml


    【解决方案1】:

    在代码隐藏中创建 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);
    

    免责声明:这未经测试。

    【讨论】:

      猜你喜欢
      • 2016-08-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-29
      • 2016-10-26
      • 1970-01-01
      相关资源
      最近更新 更多