Continued: Popup V2 does not allow any way of passing data to a popup anymore if you are not using Shell #2696
Unanswered
LeoJHarris
asked this question in
Q&A
Replies: 1 comment 1 reply
-
Because Popup inherits from View you can now set BindingContext on the Popup. e.g. using CommunityToolkit.Maui.Extensions;
using CommunityToolkit.Maui.Markup;
using CommunityToolkit.Maui.Views;
using CommunityToolkit.Mvvm.ComponentModel;
// ...
public async Task ShowPopup()
{
var popup = new Popup();
popup.BindingContext = new ProgressPopupViewModel() { ProgressText = $"LoggingInText" };
popup.BackgroundColor = Colors.Green;
popup.Content = new VerticalStackLayout
{
Children =
{
new Label { TextColor = Colors.White }.Bind(Label.TextProperty, static (ProgressPopupViewModel ctx) => ctx.ProgressText),
new Button { Text = "Close", Command = new Command(async () => { await popup.CloseAsync(); }) }
}
};
popup.Opened += Popup_Opened;
await this.ShowPopupAsync(popup);
}
private async void Popup_Opened(object? sender, EventArgs e)
{
await Task.Delay(1000); // simulate a progress delay
if (sender is Popup popup && popup.BindingContext is ProgressPopupViewModel viewModel)
{
viewModel.ProgressText = "Opened";
}
} N.B. I noticed you're still using the older MVVM syntax. Check out the blog https://devblogs.microsoft.com/dotnet/announcing-the-dotnet-community-toolkit-840/ and the corresponding new syntax (which has compiled-bindings, xmldoc advantages): [ObservableProperty]
public string ProgressText { get; set; } = string.Empty; |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Continuing discussions off the back of this issue #2693 since it was closed but feel like there is some confusion around the new V2 Popups, at least for me.
So prior to the new V2 Popups I was previously doing something like this:
Having spent time now looking at how to migrate the above to V2 Popups I don't see a way that the plugin supports it very well in the same manner as before since overload methods for
ShowPopupAsync
require Shell when providingshellParameters
.That being said however I've introduced a property called
ProgressFunc
that I would like to assigned at the time I push the popup i.e.Follows this example: https://github.com/CommunityToolkit/Maui/blob/main/samples/CommunityToolkit.Maui.Sample/Views/Popups/UpdatingPopup.xaml.cs for how I call it.
Ideally if I can set
ProgressFunc
at the time the Popup is pushed then I could call theFunc
when the Popup is opened which would behave fairly similar to how it this did in V1 Popups.I suppose the question for me becomes, assuming I have the right approach, what will the following look like so
ProgressFunc
andProgressText
can be assigned at the time the Popup is showing? Since the ViewModel is not immediately available anymore like it once was:Since this is not a Shell App the
IQueryAttributable
is not available and V2 seems like a step backwards for apps for following MVVM patterns like our is.Would be nice to get some further guidance on these breaking changes for use cases like ours as we try navigate around these changes. Thanks!
Beta Was this translation helpful? Give feedback.
All reactions