【问题标题】:WPF Flash A Border But not the ChildrenWPF Flash A Border 但不是孩子
【发布时间】:2021-10-30 06:34:13
【问题描述】:

关于如何闪烁边框而不是里面的孩子的任何想法?

我可以像这样闪烁边框:

<UserControl.Resources>
    <Storyboard x:Key="valueFlasher" RepeatBehavior="Forever">
        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="outline">
            <EasingDoubleKeyFrame KeyTime="0:0:1" Value="0.2"/>
            <EasingDoubleKeyFrame KeyTime="0:0:2" Value="1"/>
        </DoubleAnimationUsingKeyFrames>
    </Storyboard>
</UserControl.Resources>

<Border BorderBrush="Black" BorderThickness="3" CornerRadius="7" x:Name="outline">
   <!--children--> 
</Border>

但这会改变嵌套在里面的所有东西的不透明度。

我在想这样的事情:

<Border BorderThickness="3" CornerRadius="7">
    <Border.BorderBrush>
        <SolidColorBrush Color="Black" x:Name="outline"/>
    </Border.BorderBrush>
    <!--children-->
</Border>

但它似乎也不起作用。也许我的故事板找不到“大纲”,因为它是嵌套的?

提前致谢!

【问题讨论】:

    标签: c# wpf wpf-controls


    【解决方案1】:

    属性路径(UIElement.Opacity) 对 SolidColorBrush 无效,因为它不是 UIElement。


    改为使用BorderBrush.Opacity

    <Storyboard x:Key="valueFlasher" RepeatBehavior="Forever">
        <DoubleAnimationUsingKeyFrames
            Storyboard.TargetProperty="BorderBrush.Opacity" 
            Storyboard.TargetName="outline">
    
            <EasingDoubleKeyFrame KeyTime="0:0:1" Value="0.2"/>
            <EasingDoubleKeyFrame KeyTime="0:0:2" Value="1"/>
        </DoubleAnimationUsingKeyFrames>
    </Storyboard>
    

    带有这样的边框:

    <Border x:Name="outline" BorderThickness="3" CornerRadius="7">
        <Border.BorderBrush>
            <SolidColorBrush Color="Black"/>
        </Border.BorderBrush>
        <!--children-->
    </Border>
    

    或者只是Opacity

    <Storyboard x:Key="valueFlasher" RepeatBehavior="Forever">
        <DoubleAnimationUsingKeyFrames
            Storyboard.TargetProperty="Opacity" 
            Storyboard.TargetName="outline">
    
            <EasingDoubleKeyFrame KeyTime="0:0:1" Value="0.2"/>
            <EasingDoubleKeyFrame KeyTime="0:0:2" Value="1"/>
        </DoubleAnimationUsingKeyFrames>
    </Storyboard>
    

    在 SolidColorBrush 上设置 x:Name

    <Border BorderThickness="3" CornerRadius="7">
        <Border.BorderBrush>
            <SolidColorBrush x:Name="outline" Color="Black"/>
        </Border.BorderBrush>
        <!--children-->
    </Border>
    

    【讨论】:

    • 一旦我看到它,这是一个明显的修复.. 谢谢! :)
    猜你喜欢
    • 1970-01-01
    • 2012-07-26
    • 2014-11-23
    • 1970-01-01
    • 2020-07-17
    • 2011-02-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多