Closed cris-m closed 8 months ago
OnClosed event is auto-generated from the source generator, if it doesn't build it probably means that dotnet build doesn't correctly reference the source generator. Try installing the latest version of MauiReactor that doesn't require the external MauiReactor scaffold generator project:
Use this:
<ItemGroup>
<PackageReference Include="Reactor.Maui" Version="2.0.19" />
<PackageReference Include="Reactor.Maui.Canvas" Version="2.0.19" />
</ItemGroup>
instead of:
<ItemGroup>
<PackageReference Include="Reactor.Maui" Version="2.0.X-beta" />
<PackageReference Include="Reactor.Maui.Canvas" Version="2.0.X-beta" />
<PackageReference Include="Reactor.Maui.ScaffoldGenerator" Version="2.0.X-beta" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
</ItemGroup>
Thanks I will try to upgrade the package
I update to the last version but I still get the same problem.
namespace ExampleApp.Controls.Native;
[Scaffold(typeof(CommunityToolkit.Maui.Views.Popup))]
partial class Popup
{
protected override void OnAddChild(VisualNode widget, BindableObject childNativeControl)
{
if(childNativeControl is MauiControls.View content)
{
Validate.EnsureNotNull(NativeControl);
NativeControl.Content = content;
}
base.OnAddChild(widget, childNativeControl);
}
protected override void OnRemoveChild(VisualNode widget, BindableObject childNativeControl)
{
Validate.EnsureNotNull(NativeControl);
if(childNativeControl is MauiControls.View content &&
NativeControl.Content == content)
{
NativeControl.Content = null;
}
base.OnRemoveChild(widget, childNativeControl);
}
}
namespace ExampleApp.Components;
#nullable enable
public class PopupHost : Component
{
private Popup? _popup;
private bool _isShown;
private Action<object?>? _onCloseAction;
private readonly Action<Popup?>? _nativePopupCreateAction;
public PopupHost(Action<Popup?>? nativePopupCreateAction = null)
{
_nativePopupCreateAction = nativePopupCreateAction;
}
public PopupHost IsShown(bool isShown)
{
_isShown = isShown;
return this;
}
public PopupHost OnClosed(Action<Object?> action)
{
_onCloseAction = action;
return this;
}
protected override void OnMounted()
{
InitializePopup();
base.OnMounted();
}
protected override void OnPropsChanged()
{
InitializePopup();
base.OnPropsChanged();
}
private void InitializePopup()
{
if(_isShown && MauiControls.Application.Current != null)
{
MauiControls.Application.Current?.Dispatcher.Dispatch(() => {
if(ContainerPage == null || _popup == null)
return;
ContainerPage.ShowPopup(_popup);
});
}
}
public override VisualNode Render()
{
var children = Children();
return _isShown ?
new Controls.Native.Popup(r =>
{
_popup = r;
_nativePopupCreateAction?.Invoke(r);
})
{
children[0]
}
.OnClosed(OnClosed)
: null!;
}
public void OnClosed(object? sender, PopupClosedEventArgs args)
{
_onCloseAction?.Invoke(args.Result);
}
}
sorry, but I'm not sure what exactly is the problem: you can't build the project for the error: 'Popup' does not contain a definition for 'OnClosed'..., right?
can you confirm that you can't build the following project? PopupIssue.zip
I have identified the problem. Thanks for the support.
I was testing
CommunityToolkit
Popup
example and inPopupHost
class:The
OnClosed
action onPopup
create the following statement error:'Popup' does not contain a definition for 'OnClosed' and no accessible extension method 'OnClosed' accepting a first argument of type 'Popup' could be found (are you missing a using directive or an assembly reference?)