Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: XAML
Hi Everyone, I have tried converting this piece of code into csharp but have met with some issues. Anyone with ideas as to how this may be done. My current application presently is a tabbed control with an ellipse and a button. Clicking on the button is supposed to animate the ellipse. Thanks
 
Updates:
Converting
Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)"
to codes is really the issue. I am currently working on moving most of my xaml codes to c sharp so that these storyboards could be used on any element in the application. The whole idea is to take advantage of the api on http://animatedotnet.codeplex.com/.
As regards converting the xaml code to csharp, here is how far I have gone
 
DoubleAnimationUsingKeyFrames DK = new DoubleAnimationUsingKeyFrames();
TranslateTransform TT = new TranslateTransform();
EasingDoubleKeyFrame ED = new EasingDoubleKeyFrame();
ED.KeyTime = TimeSpan.FromSeconds((0));
ED.Value = 19.50;
 
ED.KeyTime = TimeSpan.FromSeconds((0.1));
ED.Value = -108;
ED.KeyTime = TimeSpan.FromSeconds((0.3));
ED.Value = -133.5;
ED.KeyTime = TimeSpan.FromSeconds((0.6));
ED.Value = -28.50;
ED.KeyTime = TimeSpan.FromSeconds((0.8));
ED.Value = 18;
ED.KeyTime = TimeSpan.FromSeconds((1.0));
ED.Value = 18;
 
DK.KeyFrames.Add(ED);
//RenderTransform RT = new RenderTransform();
TransformGroup TG = new TransformGroup();
this.RegisterName(
"TG", TG);
TG.Children.Add(TT);
//TG.Children.Add(DK);
Bal.RenderTransform = TG;
 
Storyboard.SetTargetName(DK, "TG");
Storyboard.SetTargetProperty(
DK, new PropertyPath(TranslateTransform.XProperty));
//Bal.tras
 
DoubleAnimationUsingKeyFrames DK2 = new DoubleAnimationUsingKeyFrames();
TranslateTransform TT2 = new TranslateTransform();
EasingDoubleKeyFrame ED2 = new EasingDoubleKeyFrame();
ED.KeyTime = TimeSpan.FromSeconds((0));
ED.Value = -6;
 
ED.KeyTime = TimeSpan.FromSeconds((0.1));
ED.Value = -46.5;
ED.KeyTime = TimeSpan.FromSeconds((0.3));
ED.Value = -141;
ED.KeyTime = TimeSpan.FromSeconds((0.6));
ED.Value = -154.5;
ED.KeyTime = TimeSpan.FromSeconds((0.8));
ED.Value = -157.5;
ED.KeyTime = TimeSpan.FromSeconds((1.0));
ED.Value = -157.5;
 
DK.KeyFrames.Add(ED2);
//RenderTransform RT = new RenderTransform();
TransformGroup TG2 = new TransformGroup();
this.RegisterName(
"TG2", TG2);
TG.Children.Add(TT2);
//TG.Children.Add(DK);
Bal.RenderTransform = TG2;
 
Storyboard.SetTargetName(DK2, "TG2");
Storyboard.SetTargetProperty(
DK2, new PropertyPath(TranslateTransform.YProperty));
testt.Children.Add(DK);
testt.Children.Add(DK2);
 

 
<Storyboard x:Key="iter">
			<DoubleAnimationUsingPath Duration="0:0:2" Source="X" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)" Storyboard.TargetName="ellipse">
				<DoubleAnimationUsingPath.PathGeometry>
					<PathGeometry Figures="M41,105 C41,185.90972 -23.247138,251.5 -102.5,251.5 C-181.75286,251.5 -246,185.90972 -246,105 C-246,24.090284 -181.75286,-41.5 -102.5,-41.5 C-23.247138,-41.5 41,24.090284 41,105 z"/>
				</DoubleAnimationUsingPath.PathGeometry>
			</DoubleAnimationUsingPath>
			<DoubleAnimationUsingPath Duration="0:0:2" Source="Y" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)" Storyboard.TargetName="ellipse">
				<DoubleAnimationUsingPath.PathGeometry>
					<PathGeometry Figures="M41,105 C41,185.90972 -23.247138,251.5 -102.5,251.5 C-181.75286,251.5 -246,185.90972 -246,105 C-246,24.090284 -181.75286,-41.5 -102.5,-41.5 C-23.247138,-41.5 41,24.090284 41,105 z"/>
				</DoubleAnimationUsingPath.PathGeometry>
			</DoubleAnimationUsingPath>
		</Storyboard>
Posted 27-Sep-12 2:10am
Edited 27-Sep-12 5:25am
v3
Comments
Tim Corey at 27-Sep-12 9:05am
   
Right now this question is incomplete/not a question. First, XAML is a markup language. Usually you don't "convert" it to C#. You can write XAML in your code behind, if that is what you are asking, but it is still going to output the same XAML. You can only use it in the same place you would use this XAML (you can't use it in Windows Forms, for instance). Can you explain what you are trying to accomplish and why? Also, you haven't really shown us any effort. We aren't here to do your job. Let us know where (specifically) you are stuck and we will do our best to help.
Sergey Alexandrovich Kryukov at 27-Sep-12 12:52pm
   
Absolutely. Some kind "translation" may make sense though, but OP needs to clearly and formally describe the purpose of it and the required rules of mapping one onto another.
--SA
Marcus Kramer at 27-Sep-12 11:02am
   
As Tim said, this question really does not make sense because XAML is markup and C# is code.
Sergey Alexandrovich Kryukov at 27-Sep-12 12:53pm
   
Potentially, it may make some sense, if strictly formulated. Please see my comment above.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 392
1 Nirav Prabtani 278
2 Richard Deeming 250
3 _Amy 170
4 Peter Leow 140
0 Nirav Prabtani 265
1 OriginalGriff 177
2 _Amy 170
3 Mehdi Gholam 105
4 Maciej Los 90


Advertise | Privacy | Mobile
Web03 | 2.8.140721.1 | Last Updated 27 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100