External alias in XAML

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

There is no problem with SL3 because there is no MenuItem class elsewhere in the Silverlight class library; but now I need to use another control in the Silverlight 4 Toolkit assembly, and the toolbox now defines System.Windows.Controls.MenuItem in the same assembly!

So, I need a way to tell the compiler that I want to use System.Windows.Controls.MenuItem from my old assembly, and not assembly assembly 4.

The solution is similar to the function of external aliases .

I can configure the files that I write to myself with external aliases, but how can I tell the code generator that generates ".gics" files from XAML to build, more precisely, which aliases to use?

By default, it always generates System.Windows.Controls.MenuItem variables in .gics files and, of course, without aliases, the C # compiler cannot know which assembly to use.

I am using VS 2010 Professional, but I could not find a way to change this behavior.

Thanks in advance.

+1
source share
2 answers

Finally, I found a workaround: I created a library project that wraps types from a menu library.

For instance:

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

Then I refer to this project from my real project and can use this type through my "new" namespace "Alias".

This is a kind of "heavy alias", but it seems to work.

0
source

I am afraid that the only way to get around this is the contents of the .gics file and transfer its .cs file, configure it with aliases, remove the partial keyword, and then remove x:Class from Xaml.

Growth potential will continue to work. The downside is that you need to create any new control fields yourself and add the FindName code to the copy of InitializeComponent that you now have in your .cs. Personally, I really like it, there are many reasons to give an element a name other than that it needs to be a field in the class (binding and animation are two of them). It annoys him that the fields are automatically created, and the precious load time for searching and assigning when they are never used.

0
source

Source: https://habr.com/ru/post/921867/


All Articles