1

我有一个带有内容控件的视图框。

此内容控件引用画布资源。现在,在鼠标悬停时,我想将 contentcontrol 的内容更改为另一个画布资源。

代码:

<StackPanel x:Name="ExtraActionsPanel" Background="{DynamicResource DarkGrey}" Grid.ColumnSpan="3" Height="38.5" VerticalAlignment="Bottom">
        <Viewbox x:Name="ActionIconBox1" Width="50" >
            <ContentControl Content="{DynamicResource action_message}"/>
        </Viewbox>
</StackPanel>

我的 app.xaml 资源在哪里:

<Canvas x:Key="action_message"  x:Shared="False" x:Name="action_message" Width="76" Height="76" Clip="F1 M 0,0L 76,0L 76,76L 0,76L 0,0">
        <Path Width="38" Height="39.75" Canvas.Left="19" Canvas.Top="22" Stretch="Fill" Fill="{DynamicResource VeryLightBlue}" Data="F1 M 33,51L 36.4167,61.75L 24,51L 19,51L 19,22L 57,22L 57,51L 33,51 Z "/>
</Canvas>

<Canvas x:Key="action_message_focus" x:Shared="False" x:Name="action_message_focus" Width="76" Height="76" Clip="F1 M 0,0L 76,0L 76,76L 0,76L 0,0">
        <Path Width="38" Height="39.75" Canvas.Left="19" Canvas.Top="22" Stretch="Fill" Fill="{DynamicResource Blue}" Data="F1 M 33,51L 36.4167,61.75L 24,51L 19,51L 19,22L 57,22L 57,51L 33,51 Z "/>
</Canvas>

我尝试使用情节提要和触发器来更改鼠标悬停的内容,但这给了我一个例外:无法冻结 Freezable。

<UserControl.Resources>
    <Storyboard x:Key="OnMouseEnter1">
        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(ContentControl.Content)" Storyboard.TargetName="contentControl">
            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource action_message_focus}"/>
        </ObjectAnimationUsingKeyFrames>
    </Storyboard>
</UserControl.Resources>
<UserControl.Triggers>
    <EventTrigger RoutedEvent="Mouse.MouseEnter" SourceName="ActionIconBox1">
        <BeginStoryboard Storyboard="{StaticResource OnMouseEnter1}"/>
    </EventTrigger>
</UserControl.Triggers>
4

2 回答 2

2

我尝试使用样式触发器并且它有效。下面是样式定义。

              <ContentControl>
                    <ContentControl.Style>
                        <Style TargetType="ContentControl">
                            <Setter Property="Content" Value="{StaticResource action_message}"/>
                            <Style.Triggers>
                                <Trigger Property="IsMouseOver" Value="true">
                                    <Setter Property="Content" Value="{StaticResource action_message_focus}"/>
                                </Trigger>
                            </Style.Triggers>
                        </Style>
                    </ContentControl.Style>
                </ContentControl>
于 2013-09-09T12:22:41.310 回答
0

从MSDN的Freezable Objects Overview页面:

如果以下任何一项为真,则无法冻结 Freezable:

• 它具有动画或数据绑定属性。

• 它具有由动态资源设置的属性。(有关动态资源的更多信息,请参阅资源概述。)

• 它包含无法冻结的可冻结子对象。

我猜它适用于您的Canvas控件,因为您在其中有一个Path对象,由于它使用它,它本身不能被冻结DynaimcResource

于 2013-09-09T11:36:32.640 回答