2

この質問は、SOでもかろうじて尋ねた別の質問に関連しています。

Path と TextBlock の両方を含む Canvas があります。

<Canvas>
    <Path Name="pathNodeType" StrokeThickness="1">
        <Path.Style>
            <Style>
                <Setter Property="Path.Stroke" Value="Black" />
                <Setter Property="Path.Fill" Value="LightGray" />
                <Style.Triggers>
                    <Trigger Property="Canvas.IsMouseOver" Value="True">
                        <Setter Property="Path.Stroke" Value="Blue" />
                        <Setter Property="Path.Fill" Value="LightBlue" />
                    </Trigger>
                </Style.Triggers>
            </Style>
        </Path.Style>
        <Path.Data>
            <PathGeometry>
                <PathGeometry.Figures>
                    <PathFigureCollection>
                        <PathFigure IsClosed="True" StartPoint="20,40">
                            <PathFigure.Segments>
                                <PathSegmentCollection>
                                    <ArcSegment Size="10,10" RotationAngle="45" IsLargeArc="True"  SweepDirection="Clockwise"  Point="50,40" />
                                    <LineSegment Point="50,60" />
                                    <LineSegment Point="20,60" />
                                </PathSegmentCollection>
                            </PathFigure.Segments>
                        </PathFigure>
                    </PathFigureCollection>
                </PathGeometry.Figures>
            </PathGeometry>
        </Path.Data>
    </Path>
    <TextBlock HorizontalAlignment="Left" Margin="22,40,0,0" TextWrapping="Wrap" Text="AND" VerticalAlignment="Top" FontWeight="Bold"/>
  </Canvas>

キャンバスの IsMouseOver プロパティは、マウス ポインターが描画されたパス上にあるときに期待どおりにパス スタイルをトリガーします。ただし、マウスポインターがテキストブロック (描画されたパスの真ん中に配置されている) の上にある場合、期待どおりにパススタイルがトリガーされません。

トリガーされないのはなぜですか?テキストブロックはキャンバス内にあるので、技術的に言えば、マウス ポインターもキャンバス上にあるのではないでしょうか。

これについて何か助けてくれてありがとう。

4

1 に答える 1

2

その理由は、Trigger の Property をCanvas.IsMouseOverに設定しているため、Canvas が Mouser Over のときに起動するためです。ただし、パスのスタイルでトリガーを設定すると、これはパスの領域内に制限されます。

IsMouseOver がプロパティであることは知っていますが、例として MouseEnter を使用したいと思います。MouseEnter はルーティング イベントであるため、マウスがTextBlockの上に置かれると、ルーティング イベントとして発生し、TextBlock の MouseEnter イベントが発生し、パスとキャンバスではなく、TextBlock の IsMouseOver が true になった可能性があります。現在、TextBlock の ZIndex が最高であるためです。

したがって、必要なことは、TextBlock の IsMouseOver がホバーされたときに変化しないようにすることです。

TextBlock の IsHitTestVisible="False"を設定できます。

コードは次のようになります。私はこのコードをテストしましたが、動作します!

<Canvas Background="Transparent">
    <Path Name="PathNodeType" StrokeThickness="1">
        <Path.Style>
            <Style TargetType="Path">
                <Setter Property="Stroke" Value="Black" />
                <Setter Property="Fill" Value="LightGray" />
                <Style.Triggers>
                    <Trigger Property="IsMouseOver" Value="True">
                        <Setter Property="Stroke" Value="Blue" />
                        <Setter Property="Fill" Value="LightBlue" />
                    </Trigger>
                </Style.Triggers>
            </Style>
        </Path.Style>
        <Path.Data>
            <PathGeometry>
                <PathGeometry.Figures>
                    <PathFigureCollection>
                        <PathFigure IsClosed="True" StartPoint="20,40">
                            <PathFigure.Segments>
                                <PathSegmentCollection>
                                    <ArcSegment IsLargeArc="True"
                                                Point="50,40"
                                                RotationAngle="45"
                                                Size="10,10"
                                                SweepDirection="Clockwise" />
                                    <LineSegment Point="50,60" />
                                    <LineSegment Point="20,60" />
                                </PathSegmentCollection>
                            </PathFigure.Segments>
                        </PathFigure>
                    </PathFigureCollection>
                </PathGeometry.Figures>
            </PathGeometry>
        </Path.Data>
    </Path>
    <TextBlock Margin="22,40,0,0"
               HorizontalAlignment="Left"
               VerticalAlignment="Top"
               FontWeight="Bold"
               Text="AND" IsHitTestVisible="False"
               TextWrapping="Wrap" />
</Canvas>
于 2013-08-28T02:20:28.903 に答える