As everybody knows Silverlight doesn’t support the Triggers which are most common in WPF.That means we cannot use WPF styles as it is.So obviously we need to create new styles even for Silverlight 4 which are same in behavior but using different xaml.Below are the best practices which we can follow to tackle the styles and templates in Common Code Base scenario.
- Don’t write any inline styles.Use resource dictionaries.
- Merge the resource dictionaries at the application level only.
This will solve the issue with basic styles.Think of a scenario where you are loading the styles dynamically.In WPF you can handle this using DynamicResource binding extension.But the sad thing is Silverlight doesn’t support DynamicResource. So what is the solution.
The solution which we applied was very easy.Use StaticResource in the XAML files and load the styles through code in the App.xaml.vb file.Yes it worked in WPF too.
Download sample from here to see the styles and templates in action in CCB.(See the foreground of Button.Its coming through Style)
Previous posts on Common Code Base
----------------------------------
Common Code Base 1 Introduction
You may please visit this blog for more WPF tutorial and many more.
ReplyDeletehttp://technicise.com/blogs/