scope resources to ResourceDictionary file

essamce 621 Reputation points

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

Windows Presentation Foundation
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,710 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. mister.nobody 101 Reputation points

    I'm not aware of your specific use case, but one approach I used for sharing resources between styles is this:


    <ResourceDictionary xmlns=""
        <!-- 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 xmlns=""
        <Style TargetType="{x:Type ContextMenu}">
                        <!-- Use resources from common resource dictionary -->
                        <ResourceDictionary Source="PrivateResourceDictionary.xaml"/>
            <!-- You can define your style here and use the merged resources -->

    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!

    1 person found this answer helpful.
    0 comments No comments