adospace / reactorui-maui

MauiReactor is a MVU UI framework built on top of .NET MAUI
MIT License
568 stars 47 forks source link

Accessing Public Methods for Custom Controls from .NET MAUI in MauiReactor #130

Closed ghost closed 1 year ago

ghost commented 1 year ago

Hi,

I have created a custom control/library in .NET MAUI that has some public properties and methods. While using scaffolding, I can successfully use the properties, but I am unable to use the public methods. Is there any way to call and use those methods?

Additionally, I would like to know if there is a property or API available in MauiReactor that indicates whether a view/page has been loaded, similar to the "IsLoaded" property in .NET MAUI.

Thank you.

adospace commented 1 year ago

Hi, you can access the native component by passing a function to the constructor called when it's created.

new Label(labelRef => _labelRef = labelRef)

then use the reference to call its methods:

_labelRef.CallToCustomMethod();

https://adospace.gitbook.io/mauireactor/components/accessing-native-controls

BUT: Often the need to access the native control means you're not using the correct MVU approach (could not be your case of course). Why do you need to call methods on native control?

MauiReactor pairs .NET MAUI properties and events: so to know when a view is loaded just subscribe to the OnLoaded() event as you would do in classic .NET MAUI.

new Label()
     .OnLoaded(()=>...)
adospace commented 1 year ago

closing now, please re-open if you any other questions