Skip to content

Conversation

@TheCodeTraveler
Copy link
Collaborator

@TheCodeTraveler TheCodeTraveler commented Jun 25, 2025

Description of Change

This PR adds a more complex example of using a Popup that demonstrates the following:

  1. Constructor injection, passing in a parameter using Dependency Injection via PopupService
  2. Use the Popup.Opened event to trigger an action once the Popup appears
  3. How to bind to PopupOptions
  4. How to return a result

PR Checklist

Additional information

Let's add this sample to the Popup docs @bijington

Simulator Screen Recording - iPhone 16 Pro - 2025-06-25 at 14 41 36

@TheCodeTraveler TheCodeTraveler added the pending documentation This feature requires documentation label Jun 25, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a new ComplexPopup sample to demonstrate constructor-based DI with PopupService, handling the Opened event, binding to PopupOptions, and returning a result.

  • Adds ComplexPopup view and its XAML, showcasing a delayed description update on open.
  • Implements ComplexPopupViewModel and ComplexPopupOptionsViewModel for DI, option binding, and return-value handling.
  • Hooks up a “Complex Popup” button in PopupsPage with dynamic overlay color changes and registers the popup in DI.

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
samples/CommunityToolkit.Maui.Sample/Views/Popups/ComplexPopup.xaml.cs New ComplexPopup class with DI constructor, event handler
samples/CommunityToolkit.Maui.Sample/Views/Popups/ComplexPopup.xaml Layout for the complex popup
samples/CommunityToolkit.Maui.Sample/ViewModels/Views/Popup/ComplexPopupViewModel.cs ViewModel injecting IPopupService, return command logic
samples/CommunityToolkit.Maui.Sample/ViewModels/Views/Popup/ComplexPopupOptionsViewModel.cs ViewModel for popup options (overlay color)
samples/CommunityToolkit.Maui.Sample/Pages/Views/Popup/PopupsPage.xaml.cs Added HandleComplexPopupClicked with dynamic overlay update
samples/CommunityToolkit.Maui.Sample/Pages/Views/Popup/PopupsPage.xaml Added “Complex Popup” button
samples/CommunityToolkit.Maui.Sample/MauiProgram.cs Registered ComplexPopup and ComplexPopupViewModel in DI
Comments suppressed due to low confidence (3)

samples/CommunityToolkit.Maui.Sample/ViewModels/Views/Popup/ComplexPopupViewModel.cs:4

  • [nitpick] The namespace omits the .Popup segment despite living in a Popup folder, which may lead to confusion. Consider updating it to CommunityToolkit.Maui.Sample.ViewModels.Views.Popup for consistency.
namespace CommunityToolkit.Maui.Sample.ViewModels.Views;

samples/CommunityToolkit.Maui.Sample/ViewModels/Views/Popup/ComplexPopupOptionsViewModel.cs:3

  • [nitpick] The namespace omits the .Popup segment despite the file residing in a Popup folder. Rename it to CommunityToolkit.Maui.Sample.ViewModels.Views.Popup to match the folder structure.
namespace CommunityToolkit.Maui.Sample.ViewModels.Views;

samples/CommunityToolkit.Maui.Sample/Pages/Views/Popup/PopupsPage.xaml.cs:150

  • The popupService variable is not defined in this class, causing a compilation error. Consider using the this.ShowPopupAsync<ComplexPopup, string>(complexPopupOptions) extension method or inject IPopupService into this page.
		var popupResultTask = popupService.ShowPopupAsync<ComplexPopup, string>(Navigation, complexPopupOptions);

Copy link
Contributor

@bijington bijington left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this @TheCodeTraveler i left the one comment around the example for PopupOptions binding but otherwise it looks good

pictos
pictos previously approved these changes Jul 2, 2025
Copy link
Member

@pictos pictos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I left a small comment if you want to address or adda comment for reference

Copy link
Contributor

@bijington bijington left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM from me! Just need to check the comment from @pictos regarding the Window being used

@bijington
Copy link
Contributor

@TheCodeTraveler I have added this docs PR: MicrosoftDocs/CommunityToolkit#572 it may need some more text around it but I can get to that soon. We should be good to merge and release 👍

@TheCodeTraveler TheCodeTraveler enabled auto-merge (squash) July 3, 2025 20:03
@TheCodeTraveler TheCodeTraveler removed the pending documentation This feature requires documentation label Jul 3, 2025
@TheCodeTraveler TheCodeTraveler merged commit 064ac34 into main Jul 3, 2025
11 checks passed
@TheCodeTraveler TheCodeTraveler deleted the Popup]-Add-Complex-Popup-Sample branch July 3, 2025 21:17
@github-actions github-actions bot locked and limited conversation to collaborators Jul 5, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants