Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to organize Resource Dictionary files (Style, Brush) etc in an Application?

Tags:

styles

wpf

Which is best way to organize resource files in an application? Currently in my application my resources are added inside an ResourceLib project which has this structure:

Color [folder]

  • ColorTheme1.xaml
  • ColorTheme2.xaml
  • ColorTheme2.xaml . . .

StyleResource[Folder]

  • Button.xaml
  • ToggleButton.xaml
  • TextBox.xaml
  • ListBox.xaml
  • Treeview.xaml . . . .

HeaderStyle [folder]

  • HeaderStyle1.xaml
  • HeaderStyle2.xaml . . . etc

This list will keep on increasing as the day progresses.

In the App.xaml i am referencing this Library and merging these dictionary file for one time initialization. DynamicResource is used to support theme facility.

Will there be any performance impact if continue with this structure?. Is there any advantage or performance impact if i put all these xaml in to one resource name (Style.xaml)?

What are the performance implications of a Style.xaml with 5000 lines versus splitting same into 10 different xaml files?

Finally, which is the best or accepted method?

like image 217
Kishore Kumar Avatar asked Jun 14 '11 13:06

Kishore Kumar


2 Answers

The company I work for does a lot of WPF and Silverlight work. I've developed an organization structure that we now use on all projects. That structure and write-up can be found here:

http://projekt202.com/blog/2010/xaml-organization/

like image 191
Jeff McLean Avatar answered Nov 17 '22 03:11

Jeff McLean


I am not sure if you will gain any performance as everything gets piled up in one big dictionary object anyways. Even if there is any gain at all, don't go for it. The maintainability you get in having different xaml is hard to trade off.

Having said this DynamicResource is a performance hungry operation, you might have to Freeze brushes and images wherever possibe. Add: xmlns:PresentationOptions="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options"

<SolidColorBrush x:Key="HeaderBrush" Color="Black" PresentationOptions:Freeze="True"/>
like image 36
anivas Avatar answered Nov 17 '22 04:11

anivas