我想在WPF外部完全使用XAML,特別是在XNA應用程序中。到目前爲止,我已經管理(很容易,我驚訝地承認)從XAML文件加載我的XNA應用程序中的一些數據。這些問題開始的時候,我決定,我想我的動畫類的屬性之一......什麼也沒有發生:(XAML沒有WPF - 動畫
這裏是主類我從XAML文件加載:
[ContentPropertyAttribute("Animation")]
public class Test : FrameworkContentElement
{
public string Text { get; set; }
public Vector2 Position { get; set; }
public Color Color { get; set; }
public Storyboard Animation { get; set; }
public static DependencyProperty RotationProperty =
DependencyProperty.Register("Rotation", typeof(double), typeof(Test), new PropertyMetadata(0.0));
public double Rotation { get { return (double)GetValue(RotationProperty); } set { SetValue(RotationProperty, value); } }
}
這裏XAML文件:
<l:Test xmlns:l="clr-namespace:XAMLAndXNA;assembly=XAMLAndXNA"
xmlns:a1="clr-namespace:System.Windows.Media.Animation;assembly=PresentationFramework"
xmlns:a2="clr-namespace:System.Windows.Media.Animation;assembly=PresentationCore"
Text="Testo" Position="55,60" Color="0,255,255,255">
<a1:Storyboard>
<a2:DoubleAnimation a1:Storyboard.TargetProperty="Rotation"
From="0"
To="360"
Duration="00:00:10.0"/>
</a1:Storyboard>
</l:Test>
這裏是加載和啓動動畫(未遂):
Test test = XamlReader.Load(new XmlTextReader("SpriteBatchStuff.xaml")) as Test;
test.Animation.Begin(test);
我是臨死好奇:)
真是個好主意!您是否嘗試過在普通WPF應用程序中調試動畫以查看哪些組件觸發更新? – 2010-03-05 14:51:44
我知道這是一個老問題,但我很好奇你有多遠?我一直在玩弄自己在XNA內部託管XAML的想法。即使這個問題顯示如何添加基本的動畫是一個很好的開始。 – 2012-05-05 05:48:28