DevFear
Topic Author
Posts: 52
Joined: 29 Jun 2022, 12:36

TypeArguments for generic UserControl

22 Dec 2022, 17:13

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
 
User avatar
sfernandez
Site Admin
Posts: 2983
Joined: 22 Dec 2011, 19:20

Re: TypeArguments for generic UserControl

27 Dec 2022, 12:24

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?
 
DevFear
Topic Author
Posts: 52
Joined: 29 Jun 2022, 12:36

Re: TypeArguments for generic UserControl

27 Dec 2022, 12:37

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
 
DevFear
Topic Author
Posts: 52
Joined: 29 Jun 2022, 12:36

Re: TypeArguments for generic UserControl

16 Jan 2023, 10:50

As an alternative solution, I used this approach.
Image
Image

Though I don't really like the extra action.
 
User avatar
sfernandez
Site Admin
Posts: 2983
Joined: 22 Dec 2011, 19:20

Re: TypeArguments for generic UserControl

17 Jan 2023, 21:10

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.

Who is online

Users browsing this forum: Google [Bot] and 73 guests