I usually define style and control template in App.xml under tab. So, while designing the UI, I can see the UI with the style applied in design view in Visual Studio 2008 with .NET3.5.
However, in another case, sometimes I make UserControl only project and in that case, there's no App.xml so the UI is appeared as default appearance in design view. It's hard to know actual looking in runtime.
Is there any way to apply style to UserControl, too? If there's a way to share same style and template between application project and UserControl project, that would be perfect!
Please let me know if there's a solution.
You can keep your styles in a separate ResourceDictionary in your control project. Then you need to Merge Dictionaries in the Resources block at the top of every user control:
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="MyControlLibraryStyles.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
The problem with this approach is of course that you lose any benefit that App-level styles would give you (like styling differently for different applications) because now the styles are all determined by the underlying control.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With