XAML中的外部别名 [英] External alias in XAML

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

问题描述

我当前正在使用为 Silverlight 3 4 实现菜单 ContextMenus 的库.该库在 System.Windows.Controls名称空间中定义了一个 MenuItem 类.

SL3没问题,因为Silverlight类库中的其他地方没有MenuItem类.但是现在我需要在 Silverlight 4 Toolkit程序集中使用另一个控件,并且该工具包现在在同一程序集中定义了 System.Windows.Controls.MenuItem

因此,我需要一种方法向编译器指示我要使用旧程序集中的System.Windows.Controls.MenuItem,而不是工具箱4程序集中的那个.

该解决方案似乎具有"外部别名"功能.

我可以使用外部别名来调整自己编写的文件,但是如何指示代码生成器,即一个从XAML生成".gics"文件的程序(使用汇编程序),更确切地说是要使用的别名?

默认情况下,它总是在".gics"文件中生成 System.Windows.Controls.MenuItem 变量,并且当然,如果没有别名,C#编译器将无法知道要使用哪个程序集./p>

我正在使用VS 2010 Professional,但无法找到更改此行为的选项.

谢谢.

解决方案

最后,我找到了一种解决方法: 我创建了一个库项目,该项目包装了菜单库中的类型.

例如:

namespace Alias
{
    public class MenuItem : System.Windows.Controls.MenuItem
    {
    }
}

然后,我从实际项目中引用该项目,并可以通过其新"名称空间别名"使用该类型.

这是一种沉重的别名",但似乎可行.

I'm currently using a library that implements Menus and ContextMenus for Silverlight 3 and 4. This library defines a MenuItem class in the System.Windows.Controls namespace.

No problems with SL3 because there is no MenuItem class elsewhere in the Silverlight class library; but now I need to use another control in a Silverlight 4 Toolkit assembly and the toolkit now defines a System.Windows.Controls.MenuItem in this same assembly !

So I need a way to indicate to the compiler that I want to use the System.Windows.Controls.MenuItem from my old assembly and not the one in the toolkit 4 assembly.

The solution seems the "external aliases" features.

I can tweak the files I write myself with external aliases but how to indicate to the code generator, the one that generates ".g.i.cs" files from XAML, wich assembly, more exactly which aliases, to use ?

By default it always generates System.Windows.Controls.MenuItem variables in the ".g.i.cs" files, and of course without aliases the C# compiler is unable to know which assembly to use.

I'm using VS 2010 Professional but I haven't been able to find an option to change this behaviour.

Thanks in advance.

解决方案

Finally I've found a workaround : I've created a library project that wraps the types from the menus library.

For instance :

namespace Alias
{
    public class MenuItem : System.Windows.Controls.MenuItem
    {
    }
}

I then reference this project from my real project and can use the type through their "new" namespace "Alias".

It's a kind of "heavy alias" but seems to work.

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

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