0
這裏我有在機應用資源WPF樣式故事板的另一對象的價值
<Style x:Key="ClickableText" TargetType="{x:Type Button}">
<Setter Property="BorderBrush" Value="{x:Null}"/>
<Setter Property="FontFamily" Value="/Tasks;component/Assets/Fonts/#Abel"/>
<Setter Property="Background" Value="Transparent" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border Background="{TemplateBinding Background}">
<StackPanel VerticalAlignment="Center">
<ContentPresenter x:Name="Text" HorizontalAlignment="Center" VerticalAlignment="Center"/>
<Rectangle x:Name="Rect1" Width="{Binding ActualWidth, ElementName=Text}" Height="2" Fill="{DynamicResource LightGrey}"/>
</StackPanel>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="White"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
在我添加了一個強調矩形在按鈕上的文本樣式按鈕樣式。
<Rectangle x:Name="Rect1" Width="{Binding ActualWidth, ElementName=Text}" Height="2" Fill="{DynamicResource LightGrey}"/>
我已將矩形寬度綁定爲與文本相同的寬度,以便它添加下劃線效果。
我現在想,這樣當你將鼠標懸停在按鈕矩形揭示了通過劈裂出添加效果。
我已經遠遠被觸發變量
<Trigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Duration="0:0:0.300" From="0" To="{Binding ActualWidth, ElementName=Text}" Storyboard.TargetName="Rect1" Storyboard.TargetProperty="Width" />
</Storyboard>
</BeginStoryboard>
</Trigger.EnterActions>
<Trigger.ExitActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Duration="0:0:0.300" From="{Binding ActualWidth, ElementName=Text}" To="0" Storyboard.TargetName="Rect1" Storyboard.TargetProperty="Width" />
</Storyboard>
</BeginStoryboard>
</Trigger.ExitActions>
我要鏈接的往返雙動畫的一部分,我在矩形使用的結合,但它不斷產生錯誤的同時加入該得到這個。我怎樣才能做到這一點?
我也想用這個作爲一個可重用的風格,我可以分發和保持應用程序資源。我看到其他人在代碼做到這一點通過變通方法,但我不知道你是否能在應用程序資源
任何幫助或指導,這樣做大大appriciated!
沒有看過整個問題,但基本上'Binding'非常的'StoryBoard'元素的限制,通常失敗和解決方法只存在對於一些屬性。 – grek40
[WPF動畫:綁定到故事板動畫的「To」屬性]的可能重複(https://stackoverflow.com/questions/2186933/wpf-animation-binding-to-the-to-attribute-of-storyboard-動畫) – grek40