WPF为MouseOver上的所有图像添加边框

时间:2015-12-13 23:28:43

标签: c# .net wpf

WPF新手。

我试图围绕XAML语法,但这只是几天。我想知道如何将MouseOver效果(特别是阴影)应用于此代码块中的所有Image标记:

    <ScrollViewer VerticalScrollBarVisibility="Auto">
        <WrapPanel Orientation="Horizontal">
            <WrapPanel.Style>
                <Style>
                </Style>
            </WrapPanel.Style>
            <Image Source="../Image.jpg" Width="200" Height="296" Margin="0,10,10,10"/>
            <Image Source="../Image.jpg" Width="200" Height="296" Margin="10,10,10,10"/>
            <Image Source="../Image.jpg" Width="200" Height="296" Margin="10,10,10,10"/>
            <Image Source="../Image.jpg" Width="200" Height="296" Margin="10,10,0,10"/>
        </WrapPanel>
    </ScrollViewer>

1 个答案:

答案 0 :(得分:0)

这将应用DropShadowEffect:

         <ScrollViewer VerticalScrollBarVisibility="Auto">
            <WrapPanel Orientation="Horizontal">
                <WrapPanel.Resources>
                    <Style TargetType="Image">
                        <Style.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter Property="Effect">
                                    <Setter.Value>
                                        <DropShadowEffect />
                                    </Setter.Value>
                                </Setter>
                            </Trigger>
                        </Style.Triggers>
                    </Style>
                </WrapPanel.Resources>

                <WrapPanel.Style>
                    <Style>
                    </Style>
                </WrapPanel.Style>
                <Image Source="/Image.jpg" Width="200" Height="296" Margin="0,10,10,10"/>
                <Image Source="/Image.jpg" Width="200" Height="296" Margin="10,10,10,10"/>
                <Image Source="/Image.jpg" Width="200" Height="296" Margin="10,10,10,10"/>
                <Image Source="/Image.jpg" Width="200" Height="296" Margin="10,10,0,10"/>
            </WrapPanel>
        </ScrollViewer>