0
我想使用WPF製作滑塊按鈕。所以我有這個代碼來創建一個圓,並點擊時移動它。如何在WPF中使用動畫移動EllipsePath?
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Border Background="LightGray" Margin="167,63,224,190" CornerRadius="20,20,20,20" Height="40" Width="80">
<Path Fill="Red">
<Path.Data>
<EllipseGeometry Center="20,20" RadiusX="20" RadiusY="20"/>
</Path.Data>
<Path.Effect>
<DropShadowEffect Direction="270" ShadowDepth="2" Color="Gray"></DropShadowEffect>
</Path.Effect>
<Path.Triggers>
<EventTrigger RoutedEvent="Border.MouseDown">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<PointAnimation Storyboard.TargetProperty="Center" Duration="0:0:0.3" From="20,20" To="60,20"></PointAnimation>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</Path.Triggers>
</Path>
</Border>
</Grid>
它好,它顯示了程序啓動時。但是點擊它時會拋出異常。錯誤是System.InvalidOperationException
。那麼我該如何解決這個問題呢?
是的,這就是我想和它工作得很好。但是爲什麼'PointAnimation'和'Center'財產'橢圓。不起作用?你有這個想法嗎? –
好吧,像你這樣的xaml,故事板動畫對象無法解析「中心」屬性。您從不設置「Storyboard.Target」值,讓故事板知道屬性被動畫的源對象。 –