2
我在運行時框架元素上應用DoubleAnimation
。以下是代碼片段:DoubleAnimation是/錯誤時,試圖產生XAML
foreach (FrameworkElement objInnerElement in objFrameWorkElement)
{
Point ElementPosition = new Point(Canvas.GetLeft(objInnerElement), Canvas.GetTop(objInnerElement));
DoubleAnimation db = new DoubleAnimation();
//db.From = objMoveIn.From;
db.AutoReverse = objMoveIn.AutoReverse;
if (objMoveIn.Repeat)
db.RepeatBehavior = RepeatBehavior.Forever;
db.Duration = TimeSpan.FromSeconds(objMoveIn.AnimationDuration);
Storyboard story = new Storyboard();
if (objMoveIn.ddlDirection.SelectedIndex == 0)
{
//(UIElement.RenderTransform).(TransformGroup.Children)[0].(TranslateTransform.X)
Storyboard.SetTargetProperty(db, new PropertyPath("(FrameworkElement.RenderTransform).(TranslateTransform.X)"));
//Storyboard.SetTargetProperty(db, new PropertyPath(TranslateTransform.XProperty));
db.From = 0 - ElementPosition.X;
db.To = 0;
}
else
{
Storyboard.SetTargetProperty(db, new PropertyPath("(FrameworkElement.RenderTransform).(TranslateTransform.Y)"));
//Storyboard.SetTargetProperty(db, new PropertyPath(TranslateTransform.YProperty));
db.From = 0 - ElementPosition.X;
db.To = 0;
}
story.Children.Add(db);
BeginStoryboard beginstoryboard = new BeginStoryboard();
beginstoryboard.Storyboard = story;
TranslateTransform oTransform = objInnerElement.RenderTransform as TranslateTransform;
if (oTransform == null)
{
oTransform = new TranslateTransform();
oTransform.X = 0;
oTransform.Y = 0;
objInnerElement.RenderTransform = oTransform;
}
if (objMoveIn.ddlDirection.SelectedIndex == 0)
oTransform.BeginAnimation(TranslateTransform.XProperty, db);
else
oTransform.BeginAnimation(TranslateTransform.YProperty, db);
Style objStyle = new Style();
EventTrigger objEventTrigger = new EventTrigger(FrameworkElement.LoadedEvent);
objEventTrigger.Actions.Add(beginstoryboard);
objStyle.Triggers.Add(objEventTrigger);
objInnerElement.Style = objStyle;
}
動漫作品成功,但我的問題是,當我試圖從這個生成XAML應用框架元素
string shapestring = XamlWriter.Save(element);
StringReader stringReader = new StringReader(shapestring);
XmlTextReader xmlTextReader = new XmlTextReader(stringReader);
Element DeepCopyobject = (Element)XamlReader.Load(xmlTextReader);
它會引發如下錯誤:
{「不能把字符串轉換 '的RenderTransform。(TranslateTransform.X)' 在屬性 'TargetProperty' 到類型的 對象'System.Windows.PropertyPath'。 屬性路徑無效。不能 解析類型名稱 'TranslateTransform'。錯誤的對象 'System.Windows.Media.Animation.DoubleAnimation',
請幫助我。
任何專家?請幫幫我 – Ronak 2009-08-20 10:10:30