Home > database >  Xamarin.Forms using generic types as a type argument in XAML
Xamarin.Forms using generic types as a type argument in XAML

Time:03-24

I have a custom control:

public class CustomControl<T> : ContentView
{

}

I can create an instance of this custom control with the type argument TimeSpan in XAML in Xamarin.Forms with the following:

<controls:CustomControl x:TypeArguments="x:TimeSpan" />

How can I assign the type argument as Nullable<TimeSpan> so that I have an instance of CustomControl<Nullable<TimeSpan>>? I have tried the following:

<controls:CustomControl x:TypeArguments="x:Nullable<TimeSpan>" />

CodePudding user response:

You can do it in codebehind with code like:

CustomControl<TimeSpan?> customscontrol=new CustomControl<TimeSpan?>();
  • Related