宽松的XAML [英] Loose XAML

查看:153
本文介绍了宽松的XAML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用广泛松散的XAML开发应用程序(VS2017,.> Net 4.5),并且在从另一个xaml文件引用松散的xaml文件时遇到问题.

I am developing an application (VS2017, . >Net 4.5) using extensively loose XAML and have problems with referring to a loose xaml files from another xaml file.

例如App.xaml可能类似于:

E.g. App.xaml may look like:

< Application x:Class =" CodelessXAML.App"
                                       xmlns =" http://schemas.microsoft.com/winfx/2006/xaml/presentation " ;
                                       xmlns:x =" http://schemas.microsoft.com/winfx/2006/xaml "
                                       xmlns:local ="clr-namespace:CodelessXAML"
                                       xmlns:displayElements =" clr-命名空间:CodelessXAML.DisplayElements">
    << Application.Resources>
       < ResourceDictionary Source ="MainApplicationResources.xaml"/>
    </Application.Resources>
</Application>

<Application x:Class="CodelessXAML.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:local="clr-namespace:CodelessXAML"
             xmlns:displayElements="clr-namespace:CodelessXAML.DisplayElements">
    <<Application.Resources>
        <ResourceDictionary Source="MainApplicationResources.xaml"/>
    </Application.Resources>
</Application>

如果MainApplicationResources.xaml已编译,则此方法有效,但如果未编译,则无效.
使用System.Windows.Markup.XamlReader读取并附加到App实例上可以正常工作.

And this works if MainApplicationResources.xaml is compiled, but not if it is not compiled.
Reading it and attaching to the App instance with System.Windows.Markup.XamlReader works fine.

(在这种情况下,App.xaml会被编译)

(In this case the App.xaml is compiled)

错误消息指出,即使该文件与exe文件位于同一目录中,也无法找到该文件.

The error message says that the file cannot be located even thoug it lives in the same directory as the exe file.

是否可以通过宽松的xaml访问文件,还是必须通过代码读取文件?

Is it all possible to access the file by loose xaml or does it have to be read by code ?

推荐答案


嗨EuroEager,


Hi  EuroEager,

据我所知,松散的XAML文件是包含XAML的文件,该文件没有任何关联的代码隐藏,也没有编译到应用程序中.可以将松散的XAML文件加载到Internet Explorer中,在该Internet Explorer中将呈现用户界面.

As far as I know, the loose XAML file is a file containing XAML that has no associated code-behind and is not compiled into an application.  A loose XAML file can be loaded into Internet Explorer, where the user interface will be rendered.

有关松散XAML文件的一些规则:
◾顶级元素不能是Window,而可以是Page或其他GUI元素.
◾顶级元素必须定义任何必需的名称空间
◾顶级元素不能具有x:Class属性
◾文件中的任何元素都不能具有事件处理程序
唯一支持的浏览器是Internet Explorer.

Some rules about loose XAML files:
◾The top-level element cannot be a Window, but could be a Page or other GUI element.
◾The top-level element must have any required namespaces defined
◾The top-level element cannot have a x:Class attribute
◾No elements in the file can have event handlers
◾The only browser supported is Internet Explorer.


>>是否可以通过松散的xaml访问文件,还是必须通过代码读取?

在将'; assembly = yourAssembly'添加到名称空间声明之后,您可以尝试运行您的应用程序.

You may can try to run you app after you add ';assembly=yourAssembly' to the namespace declaration.

或者使用XamlReader通过代码读取并挂钩事件处理程序.

Or use the XamlReader to read and Hook the event handlers via code.

您可以参考以下帖子.

You can refer the following post.

动态加载XAML文件:
https: //social.msdn.microsoft.com/Forums/vstudio/zh-CN/a53ff197-8703-4c6c-8726-45570304fb7b/load-xaml-file-dynamically?forum=wpf

Load XAML File dynamically:
https://social.msdn.microsoft.com/Forums/vstudio/en-US/a53ff197-8703-4c6c-8726-45570304fb7b/load-xaml-file-dynamically?forum=wpf

最好的问候,

Yohann Lu

Yohann Lu


这篇关于宽松的XAML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆