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 に答える