0
後面的代碼更改時,我經常必須動畫幾件不屬於wpf視圖的東西,比如我的電腦音量或鼠標位置。我希望通過使用wpf故事板並建立在緩動功能中來實現。動畫屬性,看看它在
例如,讓我們說,我想用下面的故事板動畫(降低音量)我的電腦上:
<Storyboard x:Key="Storyboard1">
<DoubleAnimationUsingKeyFrames
Storyboard.TargetProperty="someProperty"
Storyboard.TargetName="SomeTarget">
<EasingDoubleKeyFrame KeyTime="0:0:1" Value="0">
<EasingDoubleKeyFrame.EasingFunction>
<CircleEase EasingMode="EaseOut"/>
</EasingDoubleKeyFrame.EasingFunction>
</EasingDoubleKeyFrame>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
,並在我的代碼後面我設置與功能的卷:
MyVolumeController.SetVolume(0);
,結果我會想創建一個函數,將看起來像:(注意函數是某種形式的僞代碼)
public void AnimateProperty(Storyboard sb, Action<double> onPropertyChange)
{
var property = //sb.targetProperty;
property.OnValueChanged += (a,b)=>{
onPropertyChange(b.newValue);
}
sb.begin();// start animating
}
然後我就能夠以動畫的音量通過調用該方法爲:
AnimateProperty(
(Storyboard)this.FindResource("Storyboard1"), // storyboard
(newVal)=>{MyVolumeController.SetVolume(newVal) // action
);