2016-04-10 10 views
1

は私がThicknessAnimation InvalidOperationExceptionが

addServer = new AddServer(); 
addServer.Height = 300; 
addServer.Width = 570; 

this.RegisterName("addServerPanel", addServer); 
Main.Children.Add(addServer); 

// 252, 248, 26, 0 
addServer.Margin = new Thickness(252, 550, 26, 0); 


ThicknessAnimation thicknessAnimation = new ThicknessAnimation(); 
thicknessAnimation.From = new Thickness(252, 550, 26, 0); 
thicknessAnimation.To = new Thickness(252, 248, 26, 0); 
thicknessAnimation.Duration = new Duration(TimeSpan.FromSeconds(5)); 

Storyboard.SetTargetName(thicknessAnimation, "addServerPanel"); 
Storyboard.SetTargetProperty(thicknessAnimation, new PropertyPath(MarginProperty)); 

Storyboard storyboard = new Storyboard(); 
storyboard.Children.Add(thicknessAnimation); 

storyboard.Begin(); 

(からaddServerがユーザーコントロールである)ウィンドウメソッド内でこのコードを持っており、ストーリーボードを開始し始めたとき、私はInvalidOperationExceptionがを取得します。彼は名前addServerPanelを解決できないと言っているので、私はウィンドウがusercontrolの名前を登録していないと思う。どうすればこの問題を解決できますか?

+1

に直接設定するSetTargetメソッドを使用することができますが、[設定された目標](https://msdn.microsoft.com/en-us/にしようとしましたライブラリ/ windows/apps/windows.ui.xaml.media.animation.storyboard.settarget)を 'addServer'に直接追加するのですか? – dkozl

+0

ありがとう!それはうまくいった。これを回答として追加して、それを改善します。 – chris579

答えて

1

代わりのターゲット名を使用して、あなたはaddServerオブジェクト

Storyboard.SetTarget(thicknessAnimation, addServer); 
関連する問題