XAML下如下:当老鼠在一个文本块,其案文将扩大,当鼠叶的文本块其文本缩小。当鼠标点击的textsize冻结。

这个工作时所预期的风格的文本是直接设置的SwellingTexblock资源。然而,当风格的设StyleWrapper风格继承自SwellingTexblock,我得到以下的例外时,点击鼠标(荷兰):

坎德纳姆EnlargeFont niet binnen het namenbereik van 系统。窗户。风格vinden.

这意味着什么样的:EnlargeFont不能被发现在名字范围的系统。窗户。风格。发生了什么事?

<Window x:Class="TriggerSpike.Window2"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window2" Height="300" Width="300">
    <Window.Resources>
        <Style x:Key="SwellingTextBlock" TargetType="TextBlock">
            <Style.Triggers>
                <EventTrigger RoutedEvent="MouseEnter">
                    <EventTrigger.Actions>
                        <BeginStoryboard Name="EnlargeFont">
                            <Storyboard>
                                <DoubleAnimation Storyboard.TargetProperty="FontSize"
                                                 To="60" Duration="0:0:10"/>
                            </Storyboard>
                        </BeginStoryboard>
                    </EventTrigger.Actions>
                </EventTrigger>
                <EventTrigger RoutedEvent="MouseLeave">
                    <EventTrigger.Actions>
                        <BeginStoryboard>
                            <Storyboard>
                                <DoubleAnimation Storyboard.TargetProperty="FontSize"
                                                 To="12" Duration="0:0:.5"/>
                            </Storyboard>
                        </BeginStoryboard>
                    </EventTrigger.Actions>
                </EventTrigger>
                <EventTrigger RoutedEvent="MouseDown">
                    <PauseStoryboard BeginStoryboardName="EnlargeFont"/>
                </EventTrigger>
            </Style.Triggers>
        </Style>
        <Style x:Key="StyleWrapper" BasedOn="{StaticResource SwellingTextBlock}"
               TargetType="TextBlock"/>
    </Window.Resources>
    <StackPanel>
        <TextBlock Style="{StaticResource StyleWrapper}">test</TextBlock>
    </StackPanel>
</Window>
有帮助吗?

解决方案

看来,这种行为是"通过设计"。你必须移动的动画控件,使它的工作。

你可以找到全面解决方案 在这里,

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top