MobileBlazorBindings
MobileBlazorBindings copied to clipboard
How to map Xamarin.Forms custom class properties with blazor properties
Hi Team,
I have some doubt in blazor bindings. In Xamarin.Forms custom control, for example,having Layout Settings as custom class and it contains properties as like below code snippet
In Xamarin.Forms Main class , created property for LayoutSettings class like this
public class Main()
{
public LayoutSettings LayoutManager;
}
public class LayoutSettings:BindableObject
{
int count;
string title;
}
In blazor binding, added the LayoutManager property as RenderFragment like below code snippet
public class Main()
{
public RenderFragment LayoutManager;
}
How to map this Blazor LayoutManager property with the Xamarin.Forms LayoutManager property? Can you please share any idea for this?
Any update for this?
Any update?
Hi @jeyakasipandi you can look at some of the built-in controls with complex properties and how they use ObjectToDelegate:
https://github.com/dotnet/MobileBlazorBindings/blob/969cc4252d4bb5642569c6e154829f21e4fe39da/src/Microsoft.MobileBlazorBindings/Elements/Page.generated.cs#L46
However, a limitation of this approach is that the entire property will always be set on every update, which for most controls is harmless, but in some controls can be more problematic if they aren't expecting a property to be set again, even if it's to the same value.
Hi @Eilon
Thanks for the update. If set property (For ex public LayoutSettings LayoutManager) and using ObjectToDelegate means it works. If set property like public RenderFragment LayoutManager and using ObjectToDelegate means not able to convert LayoutManager to xamarin.Forms LayoutManager? Can you share any idea?
Sorry I think I misunderstood something. What do the Xamarin.Forms control properties look like, and what do you want them to look like in MBB? You can make them both the same type (not with RenderFragment) and use ObjectToDelegate (and the reverse) to transfer the object between the .razor file and the implementation of the element handler so that you can set it on the Xamarin.Forms control. If you provide some more details and examples I can try to provide more specific recommendations.
Hi @Eilon
Attached sample project for this.[TestSample.zip] (https://github.com/dotnet/MobileBlazorBindings/files/6310514/TestSample.zip) In sample, added RenderFragment type for HeaderContent , MainContent properties in MBB project to access .razor file as like
<HeaderContent>
<Label Text="Header"></Label>
</HeaderContent>
Header Content and Main Content properties added as View type in Xamarin.Forms project.
How to convert MBB(Blazor) HeaderContent(RenderFragment HeaderContent) to Xamarin.Forms HeaderContent(View HeaderContent)?
How to set event arguments value (like e.cancel) from MBB(Blazor) to the Xamarin.Forms event arguments?
How to access get properties(like Color Iconcolor{get;}) in razor.file?
How to set ItemTemplate as like in Xamarin.Forms in MBB? and how to set data template type properties in .razor?
Hi @jeyakasipandi I'll need some time to take a look at this. This might be a scenario that isn't well supported in MBB right now.