• <legend id='VErJn'><style id='VErJn'><dir id='VErJn'><q id='VErJn'></q></dir></style></legend>

      <bdo id='VErJn'></bdo><ul id='VErJn'></ul>

      <small id='VErJn'></small><noframes id='VErJn'>

      <i id='VErJn'><tr id='VErJn'><dt id='VErJn'><q id='VErJn'><span id='VErJn'><b id='VErJn'><form id='VErJn'><ins id='VErJn'></ins><ul id='VErJn'></ul><sub id='VErJn'></sub></form><legend id='VErJn'></legend><bdo id='VErJn'><pre id='VErJn'><center id='VErJn'></center></pre></bdo></b><th id='VErJn'></th></span></q></dt></tr></i><div id='VErJn'><tfoot id='VErJn'></tfoot><dl id='VErJn'><fieldset id='VErJn'></fieldset></dl></div>
        <tfoot id='VErJn'></tfoot>

        如何用半径和开始和停止角度绘制圆弧

        How to draw arc with radius and start and stop angle(如何用半径和开始和停止角度绘制圆弧)
      1. <tfoot id='BuK1h'></tfoot>

          <bdo id='BuK1h'></bdo><ul id='BuK1h'></ul>

            <small id='BuK1h'></small><noframes id='BuK1h'>

            <i id='BuK1h'><tr id='BuK1h'><dt id='BuK1h'><q id='BuK1h'><span id='BuK1h'><b id='BuK1h'><form id='BuK1h'><ins id='BuK1h'></ins><ul id='BuK1h'></ul><sub id='BuK1h'></sub></form><legend id='BuK1h'></legend><bdo id='BuK1h'><pre id='BuK1h'><center id='BuK1h'></center></pre></bdo></b><th id='BuK1h'></th></span></q></dt></tr></i><div id='BuK1h'><tfoot id='BuK1h'></tfoot><dl id='BuK1h'><fieldset id='BuK1h'></fieldset></dl></div>
          • <legend id='BuK1h'><style id='BuK1h'><dir id='BuK1h'><q id='BuK1h'></q></dir></style></legend>

                  <tbody id='BuK1h'></tbody>
                  本文介绍了如何用半径和开始和停止角度绘制圆弧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  如果我的 Canvas 元素的 DataContext 中有以下四个属性

                  If I have the following four properties in my DataContext of my Canvas element

                  Point  Center
                  double Radius
                  double StartAngle
                  double EndAngle
                  

                  我可以在没有任何额外代码的情况下绘制圆弧吗?

                  can I draw an arc without any extra code behind?

                  推荐答案

                  事实证明,提供自定义组件是最好的解决方案.我在我的代码中这样使用它

                  Providing a custom component turned out to be the best solution. I use it like this in my code

                  <Controls:Arc Center="{Binding Path=PreviousMousePositionPixels}" 
                           Stroke="White" 
                           StrokeDashArray="4 4"
                           SnapsToDevicePixels="True"
                           StartAngle="0" 
                           EndAngle="{Binding Path=DeltaAngle}" 
                           SmallAngle="True"
                           Radius="40" />
                  

                  SmallAngletrue 将渲染点之间的小角度,而与StartAngleEndAngle 的顺序无关.当 SmallAnglefalse 时,弧线逆时针渲染.

                  SmallAngle when true will render the small angle between the points irrespective of order of StartAngle and EndAngle. When SmallAngle is false the arc is rendered counter clockwise.

                  实现是

                  using System;
                  using System.Collections.Generic;
                  using System.Windows;
                  using System.Windows.Media;
                  using System.Windows.Shapes;
                  
                  public sealed class Arc : Shape
                  {
                      public Point Center
                      {
                          get => (Point)GetValue(CenterProperty);
                          set => SetValue(CenterProperty, value);
                      }
                  
                      // Using a DependencyProperty as the backing store for Center.  This enables animation, styling, binding, etc...
                      public static readonly DependencyProperty CenterProperty = 
                          DependencyProperty.Register(nameof(Center), typeof(Point), typeof(Arc), 
                              new FrameworkPropertyMetadata(new Point(), FrameworkPropertyMetadataOptions.AffectsRender));
                  
                      public double StartAngle
                      {
                          get => (double)GetValue(StartAngleProperty);
                          set => SetValue(StartAngleProperty, value);
                      }
                  
                      // Using a DependencyProperty as the backing store for StartAngle.  This enables animation, styling, binding, etc...
                      public static readonly DependencyProperty StartAngleProperty =
                          DependencyProperty.Register(nameof(StartAngle), typeof(double), typeof(Arc),
                              new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsRender));
                  
                      public double EndAngle
                      {
                          get => (double)GetValue(EndAngleProperty);
                          set => SetValue(EndAngleProperty, value);
                      }
                  
                      // Using a DependencyProperty as the backing store for EndAngle.  This enables animation, styling, binding, etc...
                      public static readonly DependencyProperty EndAngleProperty =
                          DependencyProperty.Register(nameof(EndAngle), typeof(double), typeof(Arc),
                              new FrameworkPropertyMetadata(Math.PI / 2.0, FrameworkPropertyMetadataOptions.AffectsRender));
                  
                      public double Radius
                      {
                          get => (double)GetValue(RadiusProperty);
                          set => SetValue(RadiusProperty, value);
                      }
                  
                      // Using a DependencyProperty as the backing store for Radius.  This enables animation, styling, binding, etc...
                      public static readonly DependencyProperty RadiusProperty =
                          DependencyProperty.Register(nameof(Radius), typeof(double), typeof(Arc),
                              new FrameworkPropertyMetadata(10.0, FrameworkPropertyMetadataOptions.AffectsRender));
                  
                      public bool SmallAngle
                      {
                          get => (bool)GetValue(SmallAngleProperty);
                          set => SetValue(SmallAngleProperty, value);
                      }
                  
                      // Using a DependencyProperty as the backing store for SmallAngle.  This enables animation, styling, binding, etc...
                      public static readonly DependencyProperty SmallAngleProperty =
                          DependencyProperty.Register(nameof(SmallAngle), typeof(bool), typeof(Arc),
                              new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
                  
                      static Arc() => DefaultStyleKeyProperty.OverrideMetadata(typeof(Arc), new FrameworkPropertyMetadata(typeof(Arc)));
                  
                      protected override Geometry DefiningGeometry
                      {
                          get
                          {
                              double a0 = StartAngle < 0 ? StartAngle + 2 * Math.PI : StartAngle;
                              double a1 = EndAngle < 0 ? EndAngle + 2 * Math.PI : EndAngle;
                  
                              if (a1 < a0)
                                  a1 += Math.PI * 2;
                  
                              SweepDirection d = SweepDirection.Counterclockwise;
                              bool large;
                  
                              if (SmallAngle)
                              {
                                  large = false;
                                  d = (a1 - a0) > Math.PI ? SweepDirection.Counterclockwise : SweepDirection.Clockwise;
                              }
                              else
                                  large = (Math.Abs(a1 - a0) < Math.PI);
                  
                              Point p0 = Center + new Vector(Math.Cos(a0), Math.Sin(a0)) * Radius;
                              Point p1 = Center + new Vector(Math.Cos(a1), Math.Sin(a1)) * Radius;
                  
                              List<PathSegment> segments = new List<PathSegment>
                              {
                                  new ArcSegment(p1, new Size(Radius, Radius), 0.0, large, d, true)
                              };
                  
                              List<PathFigure> figures = new List<PathFigure>
                              {
                                  new PathFigure(p0, segments, true)
                                  {
                                      IsClosed = false
                                  }
                              };
                  
                              return new PathGeometry(figures, FillRule.EvenOdd, null);
                          }
                      }
                  }
                  

                  这篇关于如何用半径和开始和停止角度绘制圆弧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Performance overhead of using attributes in .NET(在 .NET 中使用属性的性能开销)
                  Accessing attribute info from DTE(从 DTE 访问属性信息)
                  c# Hide a property in datagridview with datasource(c#使用数据源隐藏datagridview中的属性)
                  Extract Display name and description Attribute from within a HTML helper(从 HTML 帮助器中提取显示名称和描述属性)
                  C# Attributes and their uses(C# 属性及其用途)
                  C# - Getting all enums value by attribute(C# - 按属性获取所有枚举值)

                    <tbody id='QdAT2'></tbody>
                  <i id='QdAT2'><tr id='QdAT2'><dt id='QdAT2'><q id='QdAT2'><span id='QdAT2'><b id='QdAT2'><form id='QdAT2'><ins id='QdAT2'></ins><ul id='QdAT2'></ul><sub id='QdAT2'></sub></form><legend id='QdAT2'></legend><bdo id='QdAT2'><pre id='QdAT2'><center id='QdAT2'></center></pre></bdo></b><th id='QdAT2'></th></span></q></dt></tr></i><div id='QdAT2'><tfoot id='QdAT2'></tfoot><dl id='QdAT2'><fieldset id='QdAT2'></fieldset></dl></div>
                  • <small id='QdAT2'></small><noframes id='QdAT2'>

                      <tfoot id='QdAT2'></tfoot>

                          • <bdo id='QdAT2'></bdo><ul id='QdAT2'></ul>
                            <legend id='QdAT2'><style id='QdAT2'><dir id='QdAT2'><q id='QdAT2'></q></dir></style></legend>