hi
is it possible to make some value (ex: Double) scoped to it's ResourceDictionary file so it wouldn't be accessible elsewhere.
thanks in advance
hi
is it possible to make some value (ex: Double) scoped to it's ResourceDictionary file so it wouldn't be accessible elsewhere.
thanks in advance
I'm not aware of your specific use case, but one approach I used for sharing resources between styles is this:
PrivateResourceDictionary.xaml:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:MyApplication.Styles">
<!-- Common resources for Menu, ContextMenu and MenuItem styles -->
<!-- Do not merge this resource dictionary into any other resource dictionary!
Otherwise, the resources may become visible to other parts of the application!
Only use the resource dictionary directly from within a style or control template! -->
<!-- Border color of the menu popup -->
<SolidColorBrush x:Key="MenuPopupBorderBrush" Color="#ABABAB"/>
</ResourceDictionary>
OtherResourceDictionary.xaml:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:MyApplication.Styles">
<Style TargetType="{x:Type ContextMenu}">
<Style.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<!-- Use resources from common resource dictionary -->
<ResourceDictionary Source="PrivateResourceDictionary.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Style.Resources>
<!-- You can define your style here and use the merged resources -->
</Style>
</ResourceDictionary>
Just make sure that you merge your private resource dictionary only into the style itself but not into the using resource dictionary.
Hope this helps!
5 people are following this question.