Page 1 of 1

TypeArguments for generic UserControl

Posted: 22 Dec 2022, 17:13
by DevFear
Good afternoon. WPF supports the x:TypeArguments property, which allows you to create a generalized usercontrol. Noesis does not have this feature. Is there an alternative approach? Is it possible to add it in future versions of Noesis?
Example

Re: TypeArguments for generic UserControl

Posted: 27 Dec 2022, 12:24
by sfernandez
There are no plans to support x:TypeArguments, but I think it won't be necessary.
If you plan to have a different xaml for each implementation of your generic class, then you just specify that concrete class in the xaml:
class GenericControl<T> : UserControl  { ... }
class Test1Control : GenericControl<Test1> { ... }
<UserControl x:Class="Testing.Test1Control" >...</UserControl>
And if you plan to share the same xaml you can just use UserControl as root without x:Class and point to the same xaml in the InitializeComponent() method:
class Test1Control : GenericControl<Test1>
{
  public Test1Control() {
    InitializeComponent();
  }
  
  private void InitializeComponent() {
    Noesis.GUI.LoadComponent(this, "Assets/Xaml/GenericControl.xaml");
  }
}
Could that work for you?

Re: TypeArguments for generic UserControl

Posted: 27 Dec 2022, 12:37
by DevFear
Thank you. The second approach seems interesting.

About the first approach there are errors in WPF. When you specify a class higher in the inheritance hierarchy in XAML, the generated code .g.i.cs is inherited immediately so:
Image

Code-behind:
Image

Re: TypeArguments for generic UserControl

Posted: 16 Jan 2023, 10:50
by DevFear
As an alternative solution, I used this approach.
Image
Image

Though I don't really like the extra action.

Re: TypeArguments for generic UserControl

Posted: 17 Jan 2023, 21:10
by sfernandez
Your solution of defining a base class with the concrete type looks the best approach to make it work in both Blend and Noesis.
I don't see any other way to workaround the lack of TypeArguments, sorry.