Adding a static ResourceDictionary to UserControls before the XAML is parsed

可紊 提交于 2019-12-05 14:16:37

Did you try loading the RD inside your UserControl the same you would do it with the Application class?

<UserControl.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>                
            <ResourceDictionary Source="WpfControls;Component/GlobalResourceDictionary.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</UserControl.Resources>

This way you just specify the URI in your user control, and avoid the static members hassle altogether.

BTW, make sure to use the correct URI syntax if the RD is not in the same assembly as the UserControl. For example: pack://application:,,,/YourAssembly;component/Subfolder/YourResourceFile.xaml (more info on pack URIs)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!