从WPF中的StaticResource设置ImageSource,C#CodeBehind
我想加载注册为从WPF中的StaticResource设置ImageSource,C#CodeBehind,c#,wpf,code-behind,resourcedictionary,C#,Wpf,Code Behind,Resourcedictionary,我想加载注册为StaticResource的图像(在WPF中使用c#codebeahind),这是我的ResourceDictionary: <BitmapImage x:Key="SearchUser_NoUserPhoto" UriSource="/Shams.Win;component/Resources/Images/SearchUser/Account Disabled.png"></BitmapImage> AccountStat.Source = (Im
StaticResource
的图像(在WPF中使用c#codebeahind),这是我的ResourceDictionary
:
<BitmapImage x:Key="SearchUser_NoUserPhoto" UriSource="/Shams.Win;component/Resources/Images/SearchUser/Account Disabled.png"></BitmapImage>
AccountStat.Source = (ImageSource)TryFindResource("SearchUser_AccountEnable");
但这对我不起作用。实际上,我已经在运行时使用
即时窗口
检查了资源
集合,但它没有任何元素 这段代码对我有用:
AccountStat.Source = (ImageSource)TryFindResource("SearchUser_AccountEnable");
在
UserControl
s中使用TryFindResource
我可以访问我的ResourceDictionary
s.资源[“MyFile.png”]
当然不起作用,因为“MyFile.png”不是资源字典中的键(提示:键是“SearchUser\u NoUserPhoto”)。无论您使用Resources属性,还是TryFindResource方法都没有区别。我已经阅读了这一行关于另一个问题的内容。在接下来的几行中,我提到,资源集合
对我来说是空的!!!所以我们应该猜到,您可能不是在用ResourceDictionary谈论App类的Resources属性?
AccountStat.Source = (ImageSource)TryFindResource("SearchUser_AccountEnable");