0
下面的XAML執行以下操作:當鼠標位於文本塊上時,文本會放大,當鼠標離開文本塊時文本會縮小。點擊鼠標時,文字大小會凍結。繼承樣式在執行PauseStoryBoard動作時引發InvalidOperationException
當文本框的樣式直接設置爲SwellingTexblock資源時,此功能按預期工作。然而,當樣式設置爲從SwellingTexblock繼承StyleWrapper風格,我點擊鼠標時(荷蘭語)出現以下情況例外:
闞德NAAM EnlargeFont Niet的賓嫩 HET namenbereik麪包車 System.Windows 。風格vinden。
這意味着像這樣:在System.Windows.Style的名稱範圍中找不到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>