“System.Windows.Setter”的初始化抛出异常
我最近开始了一个使用 MS Prism 的新项目。在我的一个 UI 模块中,我有资源文件,我需要将它们添加到应用程序资源字典中。所以我编写了这段代码来做到这一点:
uri = new Uri(string.Format(@"pack://application:,,,/{0};component/{1}",
"namespacename",
"Resources.xaml"));
Application.Current.Resources.MergedDictionaries
.Add(new ResourceDictionary
{
Source = uri,
});
在我的资源文件中,我有 Datatemplate 的 Setter,看起来像这样:
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding State}" Value="Modified">
<Setter TargetName="img" Property="Source" Value="../Images/ICO/Modify.ico"/>
</DataTrigger>
<DataTrigger Binding="{Binding State}" Value="Added">
<Setter TargetName="img" Property="Source" Value="../Images/ICO/Add.ico" />
</DataTrigger>
</DataTemplate.Triggers>
问题是加载资源文件时,它会抛出“‘System.Windows.Setter’的初始化抛出异常。” 但是当我删除这个设置器时,它工作正常。 有什么想法吗?
I have recently started a new project using MS Prism. in one of my UI modules, I have resource file which I need to add them to application resource dictionary.. SO I wrote this code to do it:
uri = new Uri(string.Format(@"pack://application:,,,/{0};component/{1}",
"namespacename",
"Resources.xaml"));
Application.Current.Resources.MergedDictionaries
.Add(new ResourceDictionary
{
Source = uri,
});
In my resource files, I have Setter for Datatemplate which looks like it:
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding State}" Value="Modified">
<Setter TargetName="img" Property="Source" Value="../Images/ICO/Modify.ico"/>
</DataTrigger>
<DataTrigger Binding="{Binding State}" Value="Added">
<Setter TargetName="img" Property="Source" Value="../Images/ICO/Add.ico" />
</DataTrigger>
</DataTemplate.Triggers>
the problem is on loading resource file it throws "Initialization of 'System.Windows.Setter' threw an exception."
but when I remove this setter, it works fine.
Any Idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我需要做一些测试。但您可以尝试将图像路径更改为绝对路径,例如:
pack://application:,,,/{0};component/Images/ICO/Modify.ico
Im need to do some test. But you may try change paths to images to absolute path like :
pack://application:,,,/{0};component/Images/ICO/Modify.ico