Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,822 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
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!