1

私はそのように定義された を持っていListViewますItemContainerStyle:

                            <ListView Width="auto" 
                              SelectionMode="Single"
                              ItemContainerStyle="{StaticResource ItemContStyle}"
                               .... 

次に、トリガーを含む、baseListViewStyleに適用するいくつかの基本スタイルを定義しました。ListViewStyle

<Style x:Key="baseListViewStyle" TargetType="ListViewItem">
    <Setter Property="Height" Value="20" />
    <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
    <Style.Triggers>
        <Trigger Property="IsMouseOver" Value="True">
            <Setter Property="Foreground" Value="Red" />
        </Trigger>
    </Style.Triggers>
</Style>

ここTriggerでは、マウスが上にあるときに行が強調表示されます。良い。

私も持っていDataTriggerますListViewItem

                <Style.Triggers>
                <DataTrigger Binding="{Binding IsTestTrue}" Value="True">
                    <DataTrigger.EnterActions>
                        <BeginStoryboard Storyboard="{StaticResource SomeFunkyAnimation}" />
                    </DataTrigger.EnterActions>
                </DataTrigger>

test が true の場合、小さなフェード アニメーションが再生されます。「テストが真」の行にマウスを移動すると、アニメーションが停止し、マウスオーバースタイルが表示される場合を除いて、これはすべて機能します。

でそのスタイルをオーバーライドする方法はありますDataTriggerか?

ティア

アップデート:

SomeFunkyAnimation背景色をアニメーション化します。そのための xaml は次のとおりです。

            <Style x:Key="ItemContStyle" TargetType="{x:Type ListViewItem}" BasedOn="{StaticResource baseListViewStyle}">
            <Style.Resources>
                <Storyboard x:Key="SomeFunkyAnimation" FillBehavior="Stop">
                    <ColorAnimation Storyboard.TargetProperty="Background.Color" RepeatBehavior="Forever"  From="Red" To="Pink" Duration="0:0:3"/>
                </Storyboard>
            </Style.Resources>

MouseOverトリガーは で定義されていますbaseListViewStyle。はDataTriggerで定義されていItemContStyleます。

スタイルトリガーを削除しようとしましたが、デフォルトのスタイルが既に定義されていると思われるため、アニメーションをオーバーライドするためMouseOver、うまくいきませんでした。ListviewMouseOverDataTrigger

4

1 に答える 1

0

この問題に人生の数時間を費やした後、ようやく回避策を見つけました。何らかの理由で、ColorAnimation はマウスオーバー後にアニメーションを停止します。理由がわからない、おそらく知っているwpfバグ。解決策は、アニメーションを再調整することでした。以下は同じことを行います:

                    <Storyboard x:Key="SomeFunkyAnimation" FillBehavior="Stop">
                    <DoubleAnimation Storyboard.TargetProperty="Background.Opacity" RepeatBehavior="Forever" AutoReverse="true"  From="0.2" To="1.0" Duration="0:0:1"/>
                </Storyboard>

そして、同じ DataTrigger にバックグラウンド用の追加の Setter を追加します。

                <DataTrigger Binding="{Binding IsTestTrue}" Value="True">
                    <DataTrigger.EnterActions>
                        <BeginStoryboard Storyboard="{StaticResource SomeFunkyAnimation}" />
                    </DataTrigger.EnterActions>
                    <Setter Property="Background" Value="Red" />
                </DataTrigger>

やっと平和。

于 2010-05-19T13:21:37.453 に答える