Click here to Skip to main content
15,917,176 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to use only C# code to create all windows and controls dynamically at runtime of the application , I have many reasons why . But i am new to WPF and i want to know if there is any penalty doing it that way ? , May it cause any leaks/bugs or another issues ?
Posted

The more "dynamic" your code, the less performant, however this is mostly negligible unless you are doing some heavy stuff.
The way you design these dynamic controls (and how and when to load them) will be the determent factor here.

Memory leaks are very unlikely, bugs only if you develop them :-).

Quote:
another issues

Designing a good flow and stable dynamic creating and loading controls requires proper design. Don't jump into it too quickly. I also propose to keep stuff static as sort of a skeleton in which your dynamically created controls move. eg a mainwindow with fixed frames, a dialog with OK/Cancel buttons on which you place a user control depending on the usage, etc ...

Make sure to use "user controls" :-)


hope this helps.
good luck.
 
Share this answer
 
Comments
[no name] 25-Feb-13 6:46am    
Thank you very much , That's the answer i was expecting .
No, there's no runtime performance penalty as the XAML will just get turned into C# anyway by the XAML compiler. Not if you do it right.

But there will be a design time penalty as it will most likely take you longer to build your UIs.

Hope this helps,
Fredrik
 
Share this answer
 
Hi. If i was you , i mix two method.Because Using XAML in complex DataBinding Or DataTemplating that is very simple.in these situation if you work with C# your programming become tedious.
in my experience when i need create control dynamically such as create a table then i use C# code. and when i need create static control and layout their appearance by Style i prefer use XAML.
but it is good to know in very situation you need load UI before working with UI elements.
Choose yourself.
Good Luck.
 
Share this answer
 
v3

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900