1

当使用颜色绑定时

Background="{Binding Design.LeftBarColor}"

并执行类似的动画

<DoubleAnimation From="1" To="0.5" Storyboard.TargetName="appName"
    Storyboard.TargetProperty="(Label.Background).(SolidColorBrush.Opacity)"
    Duration="0:0:0.25"/>

所有绑定到“Design.LeftBarColor”的控件都被刷新。但我只想刷新标签的 (appName) 背景颜色。我只是尝试更改绑定模式,但这不起作用。我究竟做错了什么?

4

2 回答 2

2

Design.LeftBarColor您可以为每个标签创建一个新的背景画笔,并将新画笔的颜色绑定到Design.LeftBarColor.Color.

<Label Name="appName" ...>
    <Label.Background>
        <SolidColorBrush Color="{Binding Design.LeftBarColor.Color}"/>
    </Label.Background>
   ...
</Label>
于 2013-02-09T12:29:24.050 回答
1

不确定我对您要做什么是否正确。我会说,如果您想淡出动画控件,请不要针对画笔的不透明度。在标签顶部放置一个边框控件,并修改边框的不透明度。

示例代码在这里:

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Window.Resources>
        <SolidColorBrush x:Key="MyBrush" Color="Red"/>
    </Window.Resources>
    <Grid>
        <Border Name="Container">
            <Label Background="{StaticResource MyBrush}">
                <Label.Triggers>
                    <EventTrigger RoutedEvent="Rectangle.Loaded">
                        <BeginStoryboard>
                            <Storyboard>
                                <DoubleAnimation
            Storyboard.TargetName="Container" 
            Storyboard.TargetProperty="Opacity"
            From="1.0" To="0.0" Duration="0:0:5" 
            AutoReverse="True" RepeatBehavior="Forever" />
                            </Storyboard>
                        </BeginStoryboard>
                    </EventTrigger>
                </Label.Triggers>
                Lorem ipsum
            </Label>
        </Border>
    </Grid>
</Window>
于 2013-02-09T12:27:05.893 回答