如何通过Path触发MouseOver事件?

时间:2016-05-09 12:40:10

标签: c# wpf mahapps.metro

我希望在MouseOver上有一个突出显示的图像按钮。在MainWindow我有一个放在矩形内的画布(图标)。

<Rectangle x:Name="ejectRectangle" Width="35" Height="35" Margin="0,0,0,20" HorizontalAlignment="Center" VerticalAlignment="Center">
            <Rectangle.Fill>
                <VisualBrush Stretch="Uniform">
                    <VisualBrush.Visual>
                        <ContentControl Content="{StaticResource ejectImageButton}" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0" RenderOptions.BitmapScalingMode="HighQuality"/>
                    </VisualBrush.Visual>
                </VisualBrush>
            </Rectangle.Fill>
        </Rectangle>

在App.xaml中,我将一个触发器附加到Canvas.Path以获得突出显示效果(在这种情况下突出显示颜色为红色):

<Canvas x:Key="ejectImageButton" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Name="appbar_control_eject" Width="76" Height="76" Clip="F1 M 0,0L 76,0L 76,76L 0,76L 0,0">
            <Path Width="38" Height="30.0833" Canvas.Left="19" Canvas.Top="22.1667" Stretch="Fill" Data="F1 M 19,44.3333L 57,44.3333L 57,52.25L 19,52.25L 19,44.3333 Z M 38,22.1667L 57,41.1667L 19,41.1667L 38,22.1667 Z ">
                <Path.Style>
                    <Style TargetType="{x:Type Path}">
                        <Setter Property="Fill" Value="{Binding Source={x:Static prop:Settings.Default}, Path=theme, Converter={StaticResource idealForegroundConverter}}" />
                        <Style.Triggers>
                            <Trigger Property="IsMouseOver" Value="true">
                                <Setter Property="Fill" Value="red"/>
                            </Trigger>
                        </Style.Triggers>
                    </Style>
                </Path.Style>     
            </Path>
        </Canvas>

转换器仅用于设置更暗或更浅的颜色,具体取决于应用主题(我使用MahApps)。问题是 MouseOver事件永远不会触发。我做错了什么?

0 个答案:

没有答案