WPF - 在 IsMouseOver 上使用 ToggleButton 触发器时程序失败

WPF - Program fails when using ToggleButton Trigger on IsMouseOver

每当我尝试使用 ToggleButton 上的触发器更改路径填充时,我都会遇到奇怪的崩溃。在做了一些消除过程后,实际触发器 属性 似乎导致程序崩溃。

当它崩溃时我得到这个:

Problem signature:

Problem Event Name: CLR20r3
Problem Signature 01: briantestwpf.exe
Problem Signature 02: 1.0.0.0
Problem Signature 03: 54de1f87
Problem Signature 04: PresentationFramework
Problem Signature 05: 4.0.30319.18408
Problem Signature 06: 52312f13
Problem Signature 07: 65f2
Problem Signature 08: 5e
Problem Signature 09: System.Windows.Markup.XamlParse
OS Version: 6.1.7601.2.1.0.256.4
Locale ID: 1033
Additional Information 1: 0a9e
Additional Information 2: 0a9e372d3b4ad19135b953a78882e789
Additional Information 3: 0a9e
Additional Information 4: 0a9e372d3b4ad19135b953a78882e789

这是有问题的代码,没什么特别的,因为我想弄乱这个概念。我的项目负责人对此也很困惑。

<ToggleButton Background="Transparent" BorderThickness="1" BorderBrush="Transparent" Canvas.Left="410" Canvas.Top="384" Height="41" Width="81">
            <Canvas>

                <Path x:Name="Arrow"
        Width="32"
        Data="M0,0 L0,2 L4,6 L8,2 L0,2  "
        Fill="#FF827F96" Canvas.Left="0" Canvas.Top="-15" Stretch="Fill" Height="29" />
            </Canvas>
            <ToggleButton.Triggers>
                <Trigger Property="UIElement.IsMouseOver" Value="True">
                    <Setter TargetName="Arrow" Property="Path.Fill" Value="GhostWhite"/>
                </Trigger>
            </ToggleButton.Triggers>
        </ToggleButton>

非常感谢!

试试这个 --

<ToggleButton Background="Transparent" BorderThickness="1" BorderBrush="Transparent" Canvas.Left="410" Canvas.Top="384" Height="41" Width="81">
        <Canvas>
            <Path x:Name="Arrow" Width="32" Data="M0,0 L0,2 L4,6 L8,2 L0,2  " Fill="#FF827F96" Canvas.Left="0" Canvas.Top="-15" Stretch="Fill" Height="29" >
                <Path.Style>
                    <Style TargetType="Path">
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding Path=IsMouseOver, RelativeSource={RelativeSource AncestorType={x:Type ToggleButton}}}" Value="True">
                                <Setter Property="Stroke" Value="GhostWhite"/>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </Path.Style>
            </Path>
        </Canvas>
    </ToggleButton>