样式中的情节提要

本文关键字:样式 | 更新日期: 2023-09-27 18:20:29

在我的应用程序中,我有很多非常大的DataGridTemplateColumn-定义。我为每一列定义一种样式。例如,两列的样式如下:

<DataGridTemplateColumn.CellStyle>
    <Style TargetType="{x:Type DataGridCell}" BasedOn="{StaticResource BaseDataGridCellStyle}">
        <Setter Property="IsEditing" 
                Value="{Binding CurrentEditTarget, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, 
                                Converter={converters:EditConverter}, ConverterParameter={x:Static component:EditTarget.VariantPath}}" />
        <Setter Property="BorderBrush" Value="Blue" />      
        <Style.Triggers>
            <DataTrigger Binding="{Binding CurrentEditTarget}" Value="{x:Static component:EditTarget.VariantPath}">
                <DataTrigger.EnterActions>
                    <BeginStoryboard>
                        <Storyboard>
                            <ThicknessAnimation Storyboard.TargetProperty="(Border.BorderThickness)" FillBehavior="HoldEnd" From="4" To="0" Duration="0:0:0.5" >
                                <ThicknessAnimation.EasingFunction>
                                    <PowerEase EasingMode="EaseOut"/>
                                </ThicknessAnimation.EasingFunction>
                            </ThicknessAnimation>
                            <ThicknessAnimation Storyboard.TargetProperty="(Border.Margin)" FillBehavior="HoldEnd" From="-20,0,20,0" To="0" Duration="0:0:0.5" >
                                <ThicknessAnimation.EasingFunction>
                                    <PowerEase EasingMode="EaseOut"/>
                                </ThicknessAnimation.EasingFunction>
                            </ThicknessAnimation>
                        </Storyboard>
                    </BeginStoryboard>
                </DataTrigger.EnterActions>
                <Setter Property="attachedProperties:DataGridExtensions.FocusOnEditingColumn" Value="VariantPath"/>
            </DataTrigger>
        </Style.Triggers>
    </Style>
</DataGridTemplateColumn.CellStyle>

-

<DataGridTemplateColumn.CellStyle>
    <Style TargetType="{x:Type DataGridCell}" BasedOn="{StaticResource BaseDataGridCellStyle}">
        <Setter Property="IsEditing" 
                Value="{Binding CurrentEditTarget, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, 
                                Converter={converters:EditConverter}, ConverterParameter={x:Static component:EditTarget.OriginalPath}}" />
        <Setter Property="BorderBrush" Value="Blue" />      
        <Style.Triggers>
            <DataTrigger Binding="{Binding CurrentEditTarget}" Value="{x:Static component:EditTarget.OriginalPath}">
                <DataTrigger.EnterActions>
                    <BeginStoryboard>
                        <Storyboard>
                            <ThicknessAnimation Storyboard.TargetProperty="(Border.BorderThickness)" FillBehavior="HoldEnd" From="4" To="0" Duration="0:0:0.5" >
                                <ThicknessAnimation.EasingFunction>
                                    <PowerEase EasingMode="EaseOut"/>
                                </ThicknessAnimation.EasingFunction>
                            </ThicknessAnimation>
                            <ThicknessAnimation Storyboard.TargetProperty="(Border.Margin)" FillBehavior="HoldEnd" From="-20,0,20,0" To="0" Duration="0:0:0.5" >
                                <ThicknessAnimation.EasingFunction>
                                    <PowerEase EasingMode="EaseOut"/>
                                </ThicknessAnimation.EasingFunction>
                            </ThicknessAnimation>
                        </Storyboard>
                    </BeginStoryboard>
                </DataTrigger.EnterActions>
                <Setter Property="attachedProperties:DataGridExtensions.FocusOnEditingColumn" Value="OriginalPath"/>
            </DataTrigger>
        </Style.Triggers>
    </Style>
</DataGridTemplateColumn.CellStyle>

我想知道是否有一种方法可以将Storyboard提取到样式或资源或其他内容中。因为这是每个DataGridTemplateColumn 始终相同的样式的一部分

样式中的情节提要

这个怎么样:

<Application.Resources>
    <Storyboard x:Key="SB_Height" x:Shared="False">
        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Height)"
                Storyboard.TargetName="{DynamicResource AnimationTarget}">
            <EasingDoubleKeyFrame KeyTime="0:0:1" Value="90">
                <EasingDoubleKeyFrame.EasingFunction>
                    <CircleEase EasingMode="EaseOut" />
                </EasingDoubleKeyFrame.EasingFunction>
            </EasingDoubleKeyFrame>
        </DoubleAnimationUsingKeyFrames>
    </Storyboard>
</Application.Resources>

<Button Name="mybutton" Content="Test" Height="20">
    <Button.Triggers>
        <EventTrigger RoutedEvent="Button.Click">
            <BeginStoryboard Storyboard="{StaticResource SB_Height}"/>
        </EventTrigger>
    </Button.Triggers>
</Button>