-
Notifications
You must be signed in to change notification settings - Fork 471
[Popup] Add ComplexPopup to CommunityToolkit.Maui.Sample
#2771
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
44bc1c5
Add Complex Popup
TheCodeTraveler 3797804
Add Comments
TheCodeTraveler 68daa8e
Merge branch 'main' into Popup]-Add-Complex-Popup-Sample
TheCodeTraveler 01e455c
Merge branch 'main' into Popup]-Add-Complex-Popup-Sample
TheCodeTraveler c4bacfb
Remove ComplexPopupOptionsViewModel
TheCodeTraveler f7add1a
Add `CancellationToken.None`
TheCodeTraveler fee654f
Merge branch 'main' into Popup]-Add-Complex-Popup-Sample
TheCodeTraveler 0e5c052
Merge branch 'main' into Popup]-Add-Complex-Popup-Sample
TheCodeTraveler 136a463
Merge branch 'main' into Popup]-Add-Complex-Popup-Sample
TheCodeTraveler File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
samples/CommunityToolkit.Maui.Sample/ViewModels/Views/Popup/ComplexPopupViewModel.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| using CommunityToolkit.Mvvm.ComponentModel; | ||
| using CommunityToolkit.Mvvm.Input; | ||
|
|
||
| namespace CommunityToolkit.Maui.Sample.ViewModels.Views; | ||
|
|
||
| public partial class ComplexPopupViewModel(IPopupService popupService) : ObservableObject | ||
| { | ||
| readonly IPopupService popupService = popupService; | ||
| readonly INavigation navigation = Application.Current?.Windows[0].Page?.Navigation ?? throw new InvalidOperationException("Unable to locate INavigation"); | ||
|
|
||
| [ObservableProperty, NotifyCanExecuteChangedFor(nameof(ReturnButtonTappedCommand))] | ||
| public partial string ReturnText { get; set; } = string.Empty; | ||
|
|
||
| bool CanReturnButtonExecute => ReturnText?.Length > 0; | ||
|
|
||
| [RelayCommand(CanExecute = nameof(CanReturnButtonExecute))] | ||
| async Task OnReturnButtonTapped(CancellationToken token) | ||
| { | ||
| await popupService.ClosePopupAsync<string>(navigation, ReturnText, token); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
samples/CommunityToolkit.Maui.Sample/Views/Popups/ComplexPopup.xaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
|
|
||
| <mct:Popup xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | ||
| xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
| xmlns:mct="http://schemas.microsoft.com/dotnet/2022/maui/toolkit" | ||
| xmlns:vm="clr-namespace:CommunityToolkit.Maui.Sample.ViewModels.Views" | ||
| xmlns:system="clr-namespace:System;assembly=System.Runtime" | ||
| x:Class="CommunityToolkit.Maui.Sample.Views.Popups.ComplexPopup" | ||
| x:DataType="vm:ComplexPopupViewModel" | ||
| x:TypeArguments="system:String"> | ||
|
|
||
| <mct:Popup.Resources> | ||
| <mct:AppThemeColor Light="Black" Dark="Black" x:Key="TextColor" /> | ||
| </mct:Popup.Resources> | ||
|
|
||
| <VerticalStackLayout Spacing="12"> | ||
|
|
||
| <Label Text="Complex Popup" | ||
| TextColor="{mct:AppThemeResource TextColor}" | ||
| FontSize="24" | ||
| HorizontalTextAlignment="Center" | ||
| VerticalTextAlignment="Center" | ||
| HorizontalOptions="Center" | ||
| VerticalOptions="Center" | ||
| FontAttributes="Bold" /> | ||
|
|
||
| <Label x:Name="DescriptionLabel" | ||
| Text="This text will change upon the Opened event firing" | ||
| TextColor="{mct:AppThemeResource TextColor}" | ||
| HorizontalTextAlignment="Center" | ||
| VerticalTextAlignment="Center" | ||
| HorizontalOptions="Center" | ||
| VerticalOptions="Center" | ||
| LineBreakMode="WordWrap" /> | ||
|
|
||
| <Entry Placeholder="Enter text here then click Return" | ||
| HorizontalOptions="Center" | ||
| VerticalOptions="Center" | ||
| Text="{Binding ReturnText, Mode=OneWayToSource}" | ||
| TextColor="{mct:AppThemeResource TextColor}"/> | ||
|
|
||
| <Button Text="Return" | ||
| HorizontalOptions="Center" | ||
| VerticalOptions="Center" | ||
| Command="{Binding ReturnButtonTappedCommand}" /> | ||
|
|
||
| </VerticalStackLayout> | ||
|
|
||
| </mct:Popup> |
24 changes: 24 additions & 0 deletions
24
samples/CommunityToolkit.Maui.Sample/Views/Popups/ComplexPopup.xaml.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| using CommunityToolkit.Maui.Sample.ViewModels.Views; | ||
| using CommunityToolkit.Maui.Views; | ||
|
|
||
| namespace CommunityToolkit.Maui.Sample.Views.Popups; | ||
|
|
||
| public partial class ComplexPopup : Popup<string> | ||
| { | ||
| public ComplexPopup(ComplexPopupViewModel viewModel) | ||
| { | ||
| InitializeComponent(); | ||
|
|
||
| CanBeDismissedByTappingOutsideOfPopup = false; | ||
|
|
||
| BindingContext = viewModel; | ||
| Opened += HandlePopupOpened; | ||
| } | ||
|
|
||
| async void HandlePopupOpened(object? sender, EventArgs e) | ||
| { | ||
| // Delay for one second to ensure the user sees the previous text | ||
| await Task.Delay(TimeSpan.FromSeconds(1)); | ||
| DescriptionLabel.Text = "This Popup demonstrates constructor injection to pass in a value using Dependency Injection using PopupService, demonstrates how to use the Opened event to trigger an action once the Popup appears, demonstrates how to bind to PopupOptions, and demonstrates how to return a result."; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.