C# 为什么两个数据触发器不是';不行,就最后一个?

C# 为什么两个数据触发器不是';不行,就最后一个?,c#,wpf,xaml,C#,Wpf,Xaml,使用两个DataTrigger <Page.Resources> <Storyboard x:Key="OpenMenu"> <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Opacity)" > <EasingDoubleKeyFrame KeyTime="0" Value="0"/>

使用两个
DataTrigger

<Page.Resources>
    <Storyboard x:Key="OpenMenu">
        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Opacity)" >
            <EasingDoubleKeyFrame KeyTime="0" Value="0"/>
            <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="250"/>
        </DoubleAnimationUsingKeyFrames>

    </Storyboard>
    <Storyboard x:Key="CloseMenu">
        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Opacity)" >
            <EasingDoubleKeyFrame KeyTime="0" Value="250"/>
            <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="0"/>
        </DoubleAnimationUsingKeyFrames>
    </Storyboard>

    <Style TargetType="TextBox" x:Key="companyStyle" BasedOn="{StaticResource MaterialDesignFloatingHintTextBox}" >        
        <Style.Triggers>               

            <DataTrigger Binding="{Binding Path=SelectedValue, ElementName=comboBoxRole}" Value="AppDeveloper">
                <DataTrigger.EnterActions>
                    <BeginStoryboard Storyboard="{StaticResource OpenMenu}"/>
                </DataTrigger.EnterActions>
            </DataTrigger>

            <DataTrigger Binding="{Binding Path=SelectedValue, ElementName=comboBoxRole}" Value="EndUser">
                <DataTrigger.EnterActions>
                    <BeginStoryboard Storyboard="{StaticResource CloseMenu}"/>
                </DataTrigger.EnterActions>
            </DataTrigger>                

        </Style.Triggers>
    </Style>        

</Page.Resources>
例如,一些开发人员的字段

<!-- Company adress -->
                <TextBox x:Name="companyAdress" materialDesign:HintAssist.Hint="Company adress" Style="{StaticResource companyStyle}" Margin="0,0,0,20" FontSize="18" Foreground="RoyalBlue" FontWeight="Heavy">
                    <TextBox.Text>
                        <Binding  Mode="TwoWay" Path="CompanyAdress"  UpdateSourceTrigger="PropertyChanged">
                            <Binding.ValidationRules>
                                <DataErrorValidationRule ValidatesOnTargetUpdated="False"/>
                            </Binding.ValidationRules>
                        </Binding>
                    </TextBox.Text>
                </TextBox>

                <!-- Company website -->
                <TextBox x:Name="companyWebsite" materialDesign:HintAssist.Hint="Company Website" Style="{StaticResource companyStyle}" Margin="0,0,0,20" FontSize="18" Foreground="RoyalBlue" FontWeight="Heavy">
                    <TextBox.Text>
                        <Binding  Mode="TwoWay" Path="CompanyWebsite"  UpdateSourceTrigger="PropertyChanged">
                            <Binding.ValidationRules>
                                <DataErrorValidationRule ValidatesOnTargetUpdated="False"/>
                            </Binding.ValidationRules>
                        </Binding>
                    </TextBox.Text>
                </TextBox>

两个故事板的定义完全相同。无论如何,您可以使用
退出按钮
删除
情节提要
。此示例适用于:

<Window ...>
    <Window.Resources>
        <Storyboard x:Key="OpenMenu">
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Opacity)" >
                <EasingDoubleKeyFrame KeyTime="0" Value="1"/>
                <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="0"/>
            </DoubleAnimationUsingKeyFrames>

        </Storyboard>
        <Storyboard x:Key="CloseMenu">
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Opacity)" >
                <EasingDoubleKeyFrame KeyTime="0" Value="1"/>
                <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="1"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>

        <Style TargetType="TextBox" x:Key="companyStyle" >
            <Style.Triggers>
                <DataTrigger Binding="{Binding Path=SelectedValue, ElementName=comboBoxRole}" Value="AppDeveloper">
                    <DataTrigger.EnterActions>
                        <BeginStoryboard Name="sb" Storyboard="{StaticResource OpenMenu}"/>
                    </DataTrigger.EnterActions>
                    <DataTrigger.ExitActions>
                        <RemoveStoryboard BeginStoryboardName="sb" />
                    </DataTrigger.ExitActions>
                </DataTrigger>
                <DataTrigger Binding="{Binding Path=SelectedValue, ElementName=comboBoxRole}" Value="EndUser">
                    <DataTrigger.EnterActions>
                        <BeginStoryboard Name="sb2" Storyboard="{StaticResource CloseMenu}"/>
                    </DataTrigger.EnterActions>
                    <DataTrigger.ExitActions>
                        <RemoveStoryboard BeginStoryboardName="sb2" />
                    </DataTrigger.ExitActions>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </Window.Resources>
    <StackPanel Margin="10">
        <TextBox Style="{StaticResource companyStyle}" />
        <ComboBox x:Name="comboBoxRole" SelectedValuePath="Content">
            <ComboBoxItem>AppDeveloper</ComboBoxItem>
            <ComboBoxItem>EndUser</ComboBoxItem>
        </ComboBox>
    </StackPanel>
</Window>

应用开发者
最终用户

这是我的错误,在一个项目中,我做的不同,但它不能解决相同的问题。抱歉,编辑一篇bitI写的关于我的示例和我的相同的
双动画使用关键帧。你的工作很棒!!!!!!非常感谢。您能告诉我如何添加属性Visibility=collapse/visible吗?我写在一个问题里。还是另一个问题?“一个问题”?如果你有其他问题,请问一个新问题。谢谢)我完全理解你的意思。
<Window ...>
    <Window.Resources>
        <Storyboard x:Key="OpenMenu">
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Opacity)" >
                <EasingDoubleKeyFrame KeyTime="0" Value="1"/>
                <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="0"/>
            </DoubleAnimationUsingKeyFrames>

        </Storyboard>
        <Storyboard x:Key="CloseMenu">
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Opacity)" >
                <EasingDoubleKeyFrame KeyTime="0" Value="1"/>
                <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="1"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>

        <Style TargetType="TextBox" x:Key="companyStyle" >
            <Style.Triggers>
                <DataTrigger Binding="{Binding Path=SelectedValue, ElementName=comboBoxRole}" Value="AppDeveloper">
                    <DataTrigger.EnterActions>
                        <BeginStoryboard Name="sb" Storyboard="{StaticResource OpenMenu}"/>
                    </DataTrigger.EnterActions>
                    <DataTrigger.ExitActions>
                        <RemoveStoryboard BeginStoryboardName="sb" />
                    </DataTrigger.ExitActions>
                </DataTrigger>
                <DataTrigger Binding="{Binding Path=SelectedValue, ElementName=comboBoxRole}" Value="EndUser">
                    <DataTrigger.EnterActions>
                        <BeginStoryboard Name="sb2" Storyboard="{StaticResource CloseMenu}"/>
                    </DataTrigger.EnterActions>
                    <DataTrigger.ExitActions>
                        <RemoveStoryboard BeginStoryboardName="sb2" />
                    </DataTrigger.ExitActions>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </Window.Resources>
    <StackPanel Margin="10">
        <TextBox Style="{StaticResource companyStyle}" />
        <ComboBox x:Name="comboBoxRole" SelectedValuePath="Content">
            <ComboBoxItem>AppDeveloper</ComboBoxItem>
            <ComboBoxItem>EndUser</ComboBoxItem>
        </ComboBox>
    </StackPanel>
</Window>