Provide DataTemplate to native controls
This page describe how you can use the MauiReactor TemplateHost class to create custom native DataTemplates
[Scaffold(typeof(Syncfusion.Maui.Popup.SfPopup))]
public partial class SfPopup
{
public SfPopup Content(Func<VisualNode> render)
{
this.Set(Syncfusion.Maui.Popup.SfPopup.ContentTemplateProperty,
new MauiControls.DataTemplate(() => TemplateHost.Create(render()).NativeElement));
return this;
}
}
[Scaffold(typeof(Syncfusion.Maui.Core.SfView))]
public abstract class SfView { }
class MainPageState
{
public bool IsPopupOpen { get; set; }
}
class MainPage : Component<MainPageState>
{
public override VisualNode Render()
{
return new ContentPage("Pagina uno")
{
new VStack() {
new Label("Main page"),
new Button().Text("Apri popup").OnClicked(ApriPopup),
new SfPopup()
.Content(()=>
new VStack()
{
new Label("my label")
})
.IsOpen(State.IsPopupOpen)
.OnClosed(()=>SetState(s => s.IsPopupOpen = false, false))
}.VCenter().HCenter()
};
}
private void ApriPopup()
{
SetState(s => s.IsPopupOpen = true);
}
}Last updated