使用MergedDictionaries(UWP)拆分generic.xaml文件的正确语法是
发布时间:2020-12-14 04:25:38 所属栏目:Windows 来源:网络整理
导读:考虑我创建包含一组自定义控件的库MyCustomControlsProject的情况.我想在一个非常大的generic.xaml中放置所有这些控件的XAML代码,而不是将每个控件放在自己的XAML文件中,然后从generic.xaml引用该文件. ResourceDictionary.MergedDictionaries ResourceDicti
考虑我创建包含一组自定义控件的库MyCustomControlsProject的情况.我想在一个非常大的generic.xaml中放置所有这些控件的XAML代码,而不是将每个控件放在自己的XAML文件中,然后从generic.xaml引用该文件.
<ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="<url_syntax_file_1>" /> <ResourceDictionary Source="<url_syntax_file_2>" /> </ResourceDictionary.MergedDictionaries> 解决方案资源管理器(以及文件系统)中的文件夹结构如下所示: > MyCustomControlsProject(项目/文件夹) >主题(文件夹) > Generic.xaml(文件) > MyControl1.xaml(文件) 在过去,我使用以下语法在Silverlight和Silverlight for Win Phone中执行此操作: <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="/MyCustomControlsProject;Component/Themes/ControlTemplates/MyControl1.xaml"/> <ResourceDictionary Source="/MyCustomControlsProject;Component/Themes/ControlTemplates/MyControl2.xaml"/> </ResourceDictionary.MergedDictionaries> 对于使用此语法的Windows Phone 8.1: <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="ms-appx:///Themes/ControlTemplates/MyControl1.xaml" /> <ResourceDictionary Source="ms-appx:///Themes/ControlTemplates/MyControl2.xaml" /> </ResourceDictionary.MergedDictionaries> 这些语法都不适用于Win 10(UWP).尝试使用这些会导致运行时异常: An exception of type 'Windows.UI.Xaml.Markup.XamlParseException' occurred in MyApplication.exe but was not handled in user code WinRT information: Failed to assign to property 'Windows.UI.Xaml.ResourceDictionary.Source' because the type 'Windows.Foundation.String' cannot be assigned to the type 'Windows.Foundation.Uri'. 我也试过这种语法导致了同样的异常: <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="ControlTemplates/MyControl1.xaml" /> <ResourceDictionary Source="ControlTemplates/MyControl2.xaml" /> </ResourceDictionary.MergedDictionaries> 有趣的是,似乎app.xaml使用上面的语法没有问题. 有没有人知道generic.xaml中ResourceDictionary节点中source属性中url字符串的正确语法?或者这是UWP没有赶上的东西吗? 解决方法
正确的语法是:
<ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="ms-appx:///MyCustomControlsProject/Themes/ControlTemplates/MyControl1.xaml" /> <ResourceDictionary Source="ms-appx:///MyCustomControlsProject/Themes/ControlTemplates/MyControl2.xaml" /> </ResourceDictionary.MergedDictionaries> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- jar 在windows 启动服务,卸载服务,停止端口
- windows-server-2008 – 没有转发器的DNS
- WIN10安装office2003/7失败 WIN10安装office2003权限不足解
- active-directory – 我是否仍然拥有物理DC,即使是在Server
- windows – 为什么Perl会抱怨“包含换行符的文件名不成功”
- 如何连接到远程Windows机器以使用python执行命令?
- Windows桌面小程序+谷歌浏览器+人工智能算法 = 100+职位一键
- 在Homestead for Windows上运行黄昏测试
- Win10禁用驱动签名的命令
- 如何在Get-WmiObject Win32_Directory -filter中使用NOT LI
推荐文章
站长推荐
- 虚拟化 – 是否可以禁用Hyper-V VM的PXE引导?
- 在Windows上的Scala代码中运行shell命令似乎需要
- active-directory – 如何在Windows中设置网络用
- windows – Splunk的替代品?
- windows-phone-8 – Windows Phone 8:dllimport
- windows-installer – 任何人都有MSIINV.EXE的副
- windows-server-2008 – Windows Web Server 200
- 使用Windows Azure存储进行备份
- 版本控制 – IBM的RTC和Microsoft的TFS 2010
- 为什么在Windows上运行本地系统服务不好?
热点阅读