面向 .NET Framework 4.0。
我有一个 UserControl ( usercontrol.xaml
),其中包含一些我希望可以从应用程序的资源 ( app.xaml
) 中访问的资源。(我的 UserControl 被实例化了MainWindow.xaml
。)
到目前为止,我已经在 app.xaml 中尝试过:
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="usercontrol.xaml"/>
</ResourceDictionary.MergedDictionaries>
但 Visual Studio 对此抱怨: 查找资源字典“usercontrol.xaml”时出错。
问:如何将 UserControl 的资源添加到应用程序中,以便在运行时执行此操作:
Style style = FindResource("SomeStyleDefinedInUserControl") as Style;