VisualBrush淡入淡出动画

时间:2019-07-01 14:27:33

标签: c# wpf xaml

我正在尝试使VisualBrush在设置时自动淡入/淡出,但是很遗憾,它无法正常工作。它不会消失或消失,而不会立即消失,而完全忽略情节提要-或者我正在尝试捕获错误的事件。

<VisualBrush x:Key="CustomHatchBrush" TileMode="None" Viewport="0,0,100,100" ViewportUnits="Absolute" Viewbox="0,0,100,100" ViewboxUnits="Absolute">
    <VisualBrush.Visual>
        <Canvas>
            <Canvas.Triggers>
                <EventTrigger RoutedEvent="FrameworkElement.Loaded">
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation Duration="0:0:0.2" From="0" To="1" Storyboard.TargetProperty="(Canvas.Opacity)" RepeatBehavior="1x" />
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
                <EventTrigger RoutedEvent="FrameworkElement.Unloaded">
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation Duration="0:0:0.2" From="1" To="0" Storyboard.TargetProperty="(Canvas.Opacity)" RepeatBehavior="1x" />
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
            </Canvas.Triggers>
            <Rectangle Canvas.Top="0" Canvas.Left="0" Width="100" Height="100" Fill="Orange" />
            <Rectangle Canvas.Top="0" Canvas.Left="0" Width="100" Height="100" Fill="{DynamicResource CaretBrush}" />
        </Canvas>
    </VisualBrush.Visual>
</VisualBrush>

我通常希望在ListBoxItem的模板中将其用作BorderBrush,诸如此类:

<ControlTemplate TargetType="{x:Type ListBoxItem}">
    <Border x:Name="ca" BorderThickness="3" SnapsToDevicePixels="true" Padding="0">
        <Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="4" Background="Transparent" HorizontalAlignment="Center" VerticalAlignment="Center" SnapsToDevicePixels="true" Padding="0">
            <ContentPresenter HorizontalAlignment="Stretch" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
        </Border>
    </Border>
    <ControlTemplate.Triggers>
        <MultiDataTrigger>
            <MultiDataTrigger.Conditions>
                <Condition Binding="{Binding Prop1}" Value="true"/>
                <Condition Binding="{Binding Prop2}" Value="true"/>
            </MultiDataTrigger.Conditions>
            <Setter Property="BorderBrush" TargetName="ca" Value="{DynamicResource CustomHatchBrush}"/>
        </MultiDataTrigger>
        <MultiDataTrigger>
            <MultiDataTrigger.Conditions>
                <Condition Binding="{Binding Prop1}" Value="true"/>
                <Condition Binding="{Binding Prop2}" Value="false"/>
            </MultiDataTrigger.Conditions>
            <Setter Property="BorderBrush" TargetName="ca" Value="{DynamicResource CustomHatchBrush2}"/>
        </MultiDataTrigger>
        <DataTrigger Binding="{Binding Prop1}" Value="false">
            <Setter Property="BorderBrush" TargetName="ca" Value="Transparent"/>
        </DataTrigger>
    </ControlTemplate.Triggers>
</ControlTemplate>

我尝试了多种应用情节提要的方法,例如在绑定中,但是它总是立即完成,完全忽略了情节提要的持续时间。

我想念什么?通常,此控件可以正常工作(对象具有名称并具有多个实例,因此可能会出问题),但我无法创建想要实现的视觉效果。

0 个答案:

没有答案