Is it possible to declare a type alias name in XAML?

Is it possible in XAML to declare an alias for a type?

Let me explain an example. Given these type declarations ...

namespace Somewhere { public class Blob { … } public class BlobCollection : List<Blob> {} // "type alias" in C# } 

... the following (abbreviated) XAML must be valid:

 <BlobCollection xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns="clr-namespace:Somewhere;…"> <Blob … /> <Blob … /> </BlobCollection> 

I already know that I can define something like type aliases through inheritance (see the comment above). Suppose you wanted to do the same in XAML, how do I need to change XAML to be able to refer to BlobCollection as Blobs ?

 <Blobs xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns="clr-namespace:Somewhere;…"> <Blob … /> <Blob … /> </Blobs> 
+4
source share
1 answer

I'm not sure that you can do anti-aliasing directly in XAML, but the easiest way is to use aliases in XAML by simply subclassing the collection in code (or heck by renaming the collection class itself if it does not adversely affect the rest of your code):

 public class Blobs : BlobCollection {} 

It seems redundant to do this, but all that I can think of now.

+2
source

All Articles