2

我正在为 WPF 定义一个 Style TabControl TabItemTabItem我想在按下鼠标(左键)并且未选择时显示轻微的“按下”效果,TabItem但我找不到Trigger这个。

我试图定义一个MultiTriggerwithIsMouseLeftButtonDownIsPressed属性,但没有一个被识别。

<Style TargetType="{x:Type TabItem}">
      <Setter Property="Template">
            <Setter.Value>
                  <ControlTemplate TargetType="TabItem">
                        <Border Name="bd" BorderThickness="1,1,0,0">
                            <Grid>
                                <ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Center"
                                                  ContentSource="Header"/>    
                            </Grid>
                        </Border>
                        <ControlTemplate.Triggers>
                            <MultiTrigger>
                                <MultiTrigger.Conditions>
                                    <Condition Property="IsMouseLeftButtonDown" Value="True" /> <!--NOT RECOGNIZED-->
                                    <Condition Property="IsSelected" Value="False" />
                                </MultiTrigger.Conditions>
                                <Setter TargetName="bd" Property="Background" >
                                    <Setter.Value>
                                         <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                              <GradientStop Color="Green" Offset="0"/>
                                              <GradientStop Color="Yellow" Offset="1"/>
                                         </LinearGradientBrush>
                                    </Setter.Value>
                                 </Setter>
                            </MultiTrigger>
                       </ControlTemplate.Triggers>
                 </ControlTemplate>
            </Setter.Value>
       </Setter>
 </Style>

Trigger当鼠标左键按下时,如何设置开始动作TabItem


编辑

我试过EventTrigger了,但我没有看到下面的任何效果

<EventTrigger RoutedEvent="UIElement.PreviewMouseLeftButtonDown">
     <BeginStoryboard>
           <Storyboard>
               <ColorAnimation Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)" To="Green" Duration="0:0:3" />
           </Storyboard>
     <BeginStoryboard/>
<EventTrigger/>

可以通过这种方式以某种方式实现吗?

4

1 回答 1

0

此示例向您展示如何使用EventTriggers.

笔记

您可能必须将 Highlighting-Logic 完全设置在这些 中Triggers,因为每次都会覆盖值,所以Trigger会触发。

<EventTrigger RoutedEvent="PreviewMouseDown" >
    <EventTrigger.Actions>
        <BeginStoryboard>
            <Storyboard >
                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="bd" Storyboard.TargetProperty="Background"  Duration="0:0:3" BeginTime="0" AutoReverse="True">
                    <ObjectAnimationUsingKeyFrames.KeyFrames>
                        <DiscreteObjectKeyFrame  KeyTime="0:0:0" Value="{x:Static Brushes.Green}" />
                    </ObjectAnimationUsingKeyFrames.KeyFrames>
                </ObjectAnimationUsingKeyFrames>
            </Storyboard>
        </BeginStoryboard>
    </EventTrigger.Actions>
</EventTrigger>
<EventTrigger RoutedEvent="PreviewMouseUp" >
    <EventTrigger.Actions>
        <BeginStoryboard>
            <Storyboard >
                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="bd" Storyboard.TargetProperty="Background"  Duration="0:0:3" BeginTime="0" AutoReverse="True">
                    <ObjectAnimationUsingKeyFrames.KeyFrames>
                        <DiscreteObjectKeyFrame  KeyTime="0:0:0" Value="{x:Static Brushes.Transparent}" />
                    </ObjectAnimationUsingKeyFrames.KeyFrames>
                </ObjectAnimationUsingKeyFrames>
            </Storyboard>
        </BeginStoryboard>
    </EventTrigger.Actions>
</EventTrigger>
于 2016-07-25T08:47:55.373 回答