2

皆さん、私は WPF のパス シェイプをいじっていますが、いくつかの動作に少しイライラしています。具体的には、パスのサイズが希望どおりになりません。下の画像を見ると、パス全体が白い正方形 (パス コントロールの境界を表す) 内に収まるようにしたいのですが、円弧が少しはみ出しています。これは、実際に描画される形状ではなく、形状の描画に使用されるポイントに応じて Path 自体のサイズが変更されるためだと思います。

私の質問は、これを克服する方法を知っている人はいますか? つまり、パスの寸法を明示的に設定することは別として。形状を作成するために使用されるポイントではなく、形状に応じてパス自体のサイズを変更するために見落としたオプションはありますか? 回答ありがとうございます。

データ バインディングに関するパスの問題 ミニ言語での私のパスの問題


これは、(あるべき) 同等のコードの 2 つのバージョンです。

1)最初に、データバインディングを使用します(非常に冗長な方法で書き出されます):

<UserControl x:Class="OrbitTrapWpf.LineSegmentTool"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
         xmlns:local="clr-namespace:OrbitTrapWpf"
         mc:Ignorable="d" 
         d:DesignHeight="300" d:DesignWidth="300"
         x:Name="Root" Background="White">
<UserControl.Resources>
    <local:ArcSizeConverter x:Key="ArcSizeConverter"/>
    <local:ArcPointConverter x:Key="ArcPointConverter"/>
</UserControl.Resources>
<Path Name="path" Stroke="Black">
  <Path.Data>
    <PathGeometry>
      <PathGeometry.Figures>
        <PathFigureCollection>
          <PathFigure IsClosed="True">
            <PathFigure.StartPoint>
              <Binding ElementName="Root" Path="point0"></Binding>
            </PathFigure.StartPoint>
            <PathFigure.Segments>
              <PathSegmentCollection>
                <ArcSegment SweepDirection="Counterclockwise" >
                  <ArcSegment.Size>
                    <Binding ElementName="Root" Path="Radius" Converter="{StaticResource ArcSizeConverter}"/>
                  </ArcSegment.Size>
                  <ArcSegment.Point>
                    <Binding ElementName="Root" Path="point1" />
                  </ArcSegment.Point>
                </ArcSegment>
                <LineSegment>
                  <LineSegment.Point>
                    <Binding ElementName="Root" Path="point2" />
                  </LineSegment.Point>
                </LineSegment>
                <ArcSegment SweepDirection="Counterclockwise">
                  <ArcSegment.Size>
                    <Binding ElementName="Root" Path="Radius" Converter="{StaticResource ArcSizeConverter}"/>
                  </ArcSegment.Size>
                  <ArcSegment.Point>
                    <Binding ElementName="Root" Path="point3" />
                  </ArcSegment.Point>
                </ArcSegment>
              </PathSegmentCollection>
            </PathFigure.Segments>
          </PathFigure>
        </PathFigureCollection>
      </PathGeometry.Figures>
    </PathGeometry>
  </Path.Data>
</Path>

2) そして、これは、ミニ言語を使用して:

<UserControl x:Class="OrbitTrapWpf.LineSegmentTool"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
         xmlns:local="clr-namespace:OrbitTrapWpf"
         mc:Ignorable="d" 
         d:DesignHeight="300" d:DesignWidth="300"
         x:Name="Root" Background="White">
<UserControl.Resources>
    <local:ArcSizeConverter x:Key="ArcSizeConverter"/>
    <local:ArcPointConverter x:Key="ArcPointConverter"/>
</UserControl.Resources>
  <Grid Name="grid">
  <Path Name="path" Stroke="Black" Data="M 0.146446609406726,1.14644660940673 A 0.5,0.5 0 1 0 0.853553390593274,1.85355339059327 L 1.85355339059327,0.853553390593274 A 0.5,0.5 0 1 0 1.14644660940673,0.146446609406726 Z " />

両者はほぼ同じはずだと思っていたのですが、どうやらミニ言語版はほぼ正確なサイズで、オリジナルは大きく異なっているようです。

4

3 に答える 3

3

さて、問題を見つけて解決しました。IsLargeArcミニ言語バージョンではフラグを設定しましたが、純粋な XAML バージョンではこれをFalse. に変更したところTrue、魔法のように期待どおりの結果が得られました。

これはバグのように思えます。この場合、半円弧を描いているため、大きな円弧と小さな円弧が同じであるためです。誰かがこの動作の理由を知っているなら、それについて聞くのは素晴らしいことです!

于 2011-03-21T02:26:27.510 に答える