Wanted to get some opinions on the following idea for applications that the objects are unknown until runtime.
Say I need to create objects (i.e. Rectangular or lines or whatever...) at runtime:
Is it better create the object via C# code or create XAML code for SL engine to render those objects?
Here are some thoughts to go along with it.
a) Creating objects in C# certainly requires more code than XAML
b) Creating objects in C# will compile to IL code where as XAML code does not.
c) If I create XAML at runtime, and then try to execute XAML, wouldn't that be slower than running C# code?
for my project I use C# to generate objects (except StoryBoards, I keep them in Resources)
1. is this a lot of code
m_rc = new Rectangle();
m_rc.SetValue<double>(Canvas.LeftProperty, Convert.ToDouble(coords[0]));
m_rc.SetValue<double>(Canvas.TopProperty, Convert.ToDouble(coords[1]));
m_rc.Width = Convert.ToDouble(coords[2]) - Convert.ToDouble(coords[0]);
m_rc.Height = Convert.ToDouble(coords[3]) - Convert.ToDouble(coords[1]);
When I posted this question, I was thinking of the amount of code that takes when you're filling your objects with 5 or 6 gradients of colors. In Xaml is a lot less than in C#. But that wasn't so much of my concern (about the amount code to be written).
I just want it to be fast on client.
Now, you brought up a good point about storyboard. You're saying you create static storyboard in XAML and then at runtime you connect your "runtime objects" to the storyboard?
absolutelly correct about StoryBoards.
I have something like this in my code
m_BlinkBoard = m_control.FindName("BlinkBoard")
as Storyboard;
I'd create them in C# but at the moment there are some issues with this. Don't know what, but I read about this on forums, so decided do not test and just stored them in resources. this works very good.
Thanks for the points. As much as XAML makes creating apps easier, I think the price to pay, is when it comes to rendering of objects at runtime.
I need to do some serious testing to see if creating objects in C# is a lot faster than XAML. Theoretically it should be, but practically I don't know.
I see some apps written in SL and are very quick and some other apps are very slow. When I look at the cpu utilization, it's close to 100% but everything is very slow.
BenHayat
Participant
1097 Points
656 Posts
Brainstorming on some ideas...
Oct 25, 2007 07:35 PM | LINK
Wanted to get some opinions on the following idea for applications that the objects are unknown until runtime.
Say I need to create objects (i.e. Rectangular or lines or whatever...) at runtime:
Is it better create the object via C# code or create XAML code for SL engine to render those objects?
Here are some thoughts to go along with it.
a) Creating objects in C# certainly requires more code than XAML
b) Creating objects in C# will compile to IL code where as XAML code does not.
c) If I create XAML at runtime, and then try to execute XAML, wouldn't that be slower than running C# code?
Best Regards;
..Ben
EugenUS
Member
96 Points
120 Posts
Re: Brainstorming on some ideas...
Oct 25, 2007 07:39 PM | LINK
for my project I use C# to generate objects (except StoryBoards, I keep them in Resources)
1. is this a lot of code
m_rc = new Rectangle();
m_rc.SetValue<double>(Canvas.LeftProperty, Convert.ToDouble(coords[0]));
m_rc.SetValue<double>(Canvas.TopProperty, Convert.ToDouble(coords[1]));
m_rc.Width = Convert.ToDouble(coords[2]) - Convert.ToDouble(coords[0]);
m_rc.Height = Convert.ToDouble(coords[3]) - Convert.ToDouble(coords[1]);
for me it is not.
2. that's correct
3. very slow!
BenHayat
Participant
1097 Points
656 Posts
Re: Re: Brainstorming on some ideas...
Oct 25, 2007 07:50 PM | LINK
>>1. is this a lot of code
When I posted this question, I was thinking of the amount of code that takes when you're filling your objects with 5 or 6 gradients of colors. In Xaml is a lot less than in C#. But that wasn't so much of my concern (about the amount code to be written). I just want it to be fast on client.
Now, you brought up a good point about storyboard. You're saying you create static storyboard in XAML and then at runtime you connect your "runtime objects" to the storyboard?
Thanks for your reply!
Best Regards;
..Ben
EugenUS
Member
96 Points
120 Posts
Re: Re: Re: Brainstorming on some ideas...
Oct 25, 2007 07:56 PM | LINK
absolutelly correct about StoryBoards.
I have something like this in my code
m_BlinkBoard = m_control.FindName("BlinkBoard") as Storyboard;
I'd create them in C# but at the moment there are some issues with this. Don't know what, but I read about this on forums, so decided do not test and just stored them in resources. this works very good.
BenHayat
Participant
1097 Points
656 Posts
Re: Re: Re: Re: Brainstorming on some ideas...
Oct 25, 2007 08:06 PM | LINK
Thanks for the points. As much as XAML makes creating apps easier, I think the price to pay, is when it comes to rendering of objects at runtime.
I need to do some serious testing to see if creating objects in C# is a lot faster than XAML. Theoretically it should be, but practically I don't know.
I see some apps written in SL and are very quick and some other apps are very slow. When I look at the cpu utilization, it's close to 100% but everything is very slow.
Best Regards;
..Ben
simvouli
Member
26 Points
16 Posts
Re: Re: Re: Re: Re: Brainstorming on some ideas...
Oct 27, 2007 11:36 AM | LINK
may be this helps you to find answers about speed testing, see: http://bubblemark.com/
BenHayat
Participant
1097 Points
656 Posts
Re: Re: Re: Re: Re: Re: Brainstorming on some ideas...
Oct 27, 2007 11:59 AM | LINK
Thanks!
Best Regards;
..Ben