none
请问wpf下如何更改多个控件的相同属性呢? RRS feed

  • 问题

  • 刚接触WPF不久,现在有多个Border控件,都应用了相同的Style样式,当单击其中一个Border时,如何将其他的Border背景色变为透明色呢?

    这个能在Style中做出设定么?

    Style如下:

    <Style x:Key="BorderButton"  TargetType="Border">
    
                <Style.Triggers>
                    <Trigger Property="IsMouseOver" Value="True">
                        <Setter Property="Background">
                            <Setter.Value>
                                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                    <GradientStop Color="#71FFFFFF" Offset="0.776" />
                                    <GradientStop Color="Transparent" Offset="0" />
                                </LinearGradientBrush>
                            </Setter.Value>
                        </Setter>
                    </Trigger>
                    <EventTrigger RoutedEvent="Border.MouseLeftButtonDown">
                        <BeginStoryboard>
                            <Storyboard>
                                <ObjectAnimationUsingKeyFrames BeginTime="00:00:00"  Storyboard.TargetProperty="Background">
                                    <DiscreteObjectKeyFrame KeyTime="00:00:0.1" >
                                        <DiscreteObjectKeyFrame.Value>
                                            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                                <GradientStop Color="#71FFFFFF" Offset="0.776" />
                                                <GradientStop Color="Transparent" Offset="0" />
                                            </LinearGradientBrush>
                                        </DiscreteObjectKeyFrame.Value>
                                    </DiscreteObjectKeyFrame>
                                </ObjectAnimationUsingKeyFrames>
                            </Storyboard>
                        </BeginStoryboard>
                    </EventTrigger>
                </Style.Triggers>
                <EventSetter Event="MouseLeftButtonDown" Handler="Border_MouseLeftButtonDown"/>
                <Setter Property="Background" Value="Transparent"/>
            </Style>

    请问我如何操作,才能在触发MouseLeftButtonDown的时候,更改同样应用了这个样式的其他Border的Background属性为透明色呢?

    求各位大神赐教

    2014年1月7日 12:31

全部回复