可以WPF应用程序部署,而不编译XAML? [英] Can a wpf application be deployed without compiling the xaml?

查看:168
本文介绍了可以WPF应用程序部署,而不编译XAML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能以这样一种方式,XAML文件可以在运行时操纵部署WPF windows应用程序?如果可能的话,我会想象这会工作类似于一个asp.net应用程序,它可以部署在.aspx页面的内容,然后再在运行时编译刚刚好时间。

Is it possible to deploy a WPF windows application in such a way that the xaml files can be manipulated at run-time? If possible, I would imagine this would work similar to an asp.net application that can deploy the .aspx pages as content, which are then compiled just-in-time at run-time.

我想允许通过编辑XAML屏幕的简单的布局,以在运行时进行编辑。有谁知道这是可能的吗?

I'd like to allow the simple layout of a screen to be edited at run-time by editing the XAML. Does anyone know if this is possible?

编辑::当我指的是XAML文件,我指的是相应的XAML我的UIElement类。换句话说,我已经定义使用​​XAML和code-背后,继承,事件处理程序,程序集引用,等用户控件类时,部署时间到来的时候,我希望能够保持在code-背后功能,但仍然允许XAML进行编辑。

When I refer to xaml files, I mean the corresponding xaml to my UIElement classes. In other words, I have defined UserControl classes using Xaml and code-behind, inheritance, event handlers, assembly references, etc. When deployment time comes, I'd like to be able to keep the code-behind functionality but still allow the xaml to be edited.

推荐答案

我还有一个建议,你 - 真正的问题是:

I have another suggestion for you - the real question was:

我想,以允许通过编辑XAML屏幕的简单的布局,以在运行时进行编辑。有谁知道这是可能的吗?

"I'd like to allow the simple layout of a screen to be edited at run-time by editing the XAML. Does anyone know if this is possible?"

答案肯定是是!而且有许多方法可以达到这个目的,使得当然一些假设

The answer is definitely, "YES"! And there are many ways to achieve this, making a few assumptions of course.

如果您有没有必要在你的XAML的动态部分来处理事件或编写自定义值转换器(或其他任何通常会走在code后面),那么你可以简单地使用的XamlReader类解析一个XAML文件或包含字符串的XAML。因为你只是编辑的布局,我想到的是,这些假设成立。

If you have no need to handle events or write custom value converters (or anything else that would normally go in the code behind) in the "dynamic" part of your XAML, then you can simply use the XamlReader class to parse a XAML file or string containing XAML. Since you are merely editing the layout, I expect that these assumption holds true.

所以,这里是我会做什么:

So, here is what I would do:

1)写所有的自定义控制,数据模型,价值转换器等,并坚持在一个集会。

1) Write all your custom controls, data models, value converters, etc, and stick them in an assembly.

2)加载该程序集,或者通过让你的应用程序中引用它,或者动态加载 - 双方将努力

2) Load that assembly, either by having your app reference it or load it dynamically - both will work.

3)创建一个字符串/文件/资源​​(随你挑),有你的XAML,做布局,完成您的.NET命名空间的一个XML命名空间的映射。请确保你没有一个x:类的根元素属性,因为你没有code隐藏文件!该字符串将使用标准WPF控件(如StackPanel中)布局自定义控件。 (当然你也可以编写自定义布局控件)。

3) Create a string/file/resource (take your pick) that has your XAML that does layout, complete with the mapping of your .NET namespace to an XML namespace. Make sure you do not have an "x:Class" attribute on the root element as you have no code behind file! The string would use the standard WPF controls (like the StackPanel) to layout your custom controls. (Of course you can also write custom layout controls).

4)允许用户编辑这个串。当他们已经​​编辑它,使用的XamlReader来解析文件,然后在窗口中显示生成的UIElement。

4) Allow the user to edit this string. When they have edited it, use the XamlReader to parse the file and then display the resulting UIElement in your window.

BINGO!

一个问题 - 每次的XAML改变时,GUI被抛出,并创建一个新的。如果你的GUI是sateful(即使当前光标位置是很重要的),用户将很快生气pretty的。这取决于你打算使用的是 - 这可能不是一个问题。

One problem - everytime the XAML is changed, the GUI is tossed and a new one created. If your GUI is sateful (even if the current caret position is important), the user will get annoyed pretty quickly. It depend on what your intend use is - this may not be an issue.

我预计一些更多的工作,你可以写,用于指代您尝试布局份的MarkupExtension。它们可以被重新使用这种方式时的布局的变化。

I expect that with some more work, you could write a MarkupExtension that is used to refer to the parts that you are trying to layout. This way they could be reused when the layout changes.

我希望这是显而易见的。如果没有,让我知道,我可以在这个概念扩展 - 它会成为一个不错的博客条目

I hope this is clear. If not, let me know and I can expand on the concept - it'd make a nice blog entry.

这篇关于可以WPF应用程序部署,而不编译XAML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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