可以编写条件XAML吗? [英] Can one write Conditional XAML?

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

问题描述

根据是否在Silverlight的WPF应用程序中使用它,有一种方法可以使相同的xaml文档有所不同.

在C#中可以执行以下操作

It there a way to make the same xaml document be different depending on whether it is used in a WPF app of a Silverlight one.

in C# one can do the following

#if !SILVERLIGHT
  //Some code
#else

 //Some different code
#end if 



有没有办法在Xaml中进行等效操作.
如果在WPF和Silverlight项目中使用相同的xaml文件,这将非常有用.

我怀疑答案是否定的,但我认为值得一问.
谢谢
Ken



Is there a way to do the equivalent in Xaml.
This would be very useful if one uses same xaml file in both WPF and Silverlight projects.

I suspect the answer is no, but I thought it worth asking.
Thanks
Ken

推荐答案

您是对的,答案是否".

以下文章提供了一种解决方法,尽管这是一种颠簸的方式...

You are right, the answer is "no".

The following article offers a workaround, although it''s a bumpy way to go...

http://blogs.msdn.com/b/blemmon/archive/2009/04/29/using-the-preprocessor-to-share-incompatible-xaml-between-sl-and-wpf-part-1.aspx


不,但是您可以在设置样式的代码或设置属性的转换器中编写条件代码.

我们的代码中没有条件性的内容,但是几乎所有的布局/内容都是在读取数据库设置之后确定的,这就是我们的工作方式.
No, but you can write conditional code in the code behind that sets styles or in converters that set properties.

We don''t have conditional stuff in our code, but pretty much the entire layout/content is determined after reading database settings, and that''s how we do it.


不,
它们都将在不同的框架上运行,因此我们不能对两者使用相同的XAP.
问候
siraz
No,
both of them will run on different framework so we cannot use the same XAP for both.

Regards
siraz


这篇关于可以编写条件XAML吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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