It is possible to specify a class with type parameters in XAML (see step 2), but the generated (partial) definition will cause a runtime failure.
The class is successfully instantiated according to its definitions in XAML and code-behind
Runtime failure at line global::Xamarin.Forms.Xaml.Extensions.LoadFromXaml(this, typeof(GenericClass<T>));
An exception of type 'Xamarin.Forms.Xaml.XamlParseException' occurred in Xamarin.Forms.Xaml.dll but was not handled in user code
Additional information: No embeddedresource found for Project.GenericClass`1[ConcreteType]
Defining generic classes in Xaml is not supported at this time.
step 2 should also be
Add '`1' to x:Class
I'm keeping this as a feature request
Thanks for picking it up.
As for step 2, it is <T> encoded using XML entities < (less than) and > (greater than), or am I missing something? Perhaps you're missing entities in your markdown (things between actual < and > get removed I've noticed)?
@developMediaSoft The docs for x:Class say it uses the same format as Type.FullName which would mean a generic class such as List<String> would be written as System.Collections.Generic.List`1[System.String]
Thus your step 2 would be `1[T] rather than <T>
I think there would be some issues with knowing the list of concrete types that could be instantiated - unless T was internal and all derived classes were sealed??
I have a number of XAML pages which are concrete implementations of a Generic base class which works for my situation - but I don't think that is what you are looking for. (See x:TypeArguments)
Thank you for explaining that @CZEMacLeod, I must say I've only learned this fact about x:Class from you now. My use of entities was a guess.
What would knowing concrete types be necessary for?
Indeed simply parameterizing an already-defined generic class in XAML utilizing x:TypeArguments is not what I'm after, but I appreciate you mentioning it for the sake of those who might find this thread via search engines.
I don't foresee this being implemented in the coming months by the XF team, and no one volunteered, so I'll close it. We'll reopen it if needed, or I'm sure we can come up with that exact same idea again
Our Xamarin.Forms-based project is in a similar state as this issue
So this will never be implemented, right?