File tree 15 files changed +1309
-168
lines changed
15 files changed +1309
-168
lines changed Original file line number Diff line number Diff line change @@ -19,14 +19,20 @@ public PopupsPage(PopupsViewModel multiplePopupViewModel, IPopupService popupSer
19
19
20
20
async void HandleSimplePopupButtonClicked ( object sender , EventArgs e )
21
21
{
22
- await popupService . ShowPopupAsync < SimplePopup > ( Navigation , new PopupOptions
22
+ var queryAttributes = new Dictionary < string , object >
23
23
{
24
- Shape = new RoundRectangle
24
+ [ "DescriptionLabel" ] = "This is a popup where this text is being passed in using IQueryAttributable"
25
+ } ;
26
+
27
+ await popupService . ShowPopupAsync < SimplePopup > ( Shell . Current , new PopupOptions
25
28
{
26
- CornerRadius = new CornerRadius ( 4 ) ,
27
- Stroke = Colors . White
28
- } ,
29
- } , CancellationToken . None ) ;
29
+ Shape = new RoundRectangle
30
+ {
31
+ CornerRadius = new CornerRadius ( 4 ) ,
32
+ Stroke = Colors . White
33
+ }
34
+ } , queryAttributes
35
+ , CancellationToken . None ) ;
30
36
}
31
37
32
38
async void HandleButtonPopupButtonClicked ( object sender , EventArgs e )
Original file line number Diff line number Diff line change 3
3
4
4
namespace CommunityToolkit . Maui . Sample . ViewModels . Views ;
5
5
6
- public sealed partial class CsharpBindingPopupViewModel : BaseViewModel
6
+ public sealed partial class CsharpBindingPopupViewModel : BaseViewModel , IQueryAttributable
7
7
{
8
8
[ ObservableProperty ]
9
- public partial string Title { get ; set ; } = "C# Binding Popup" ;
9
+ public partial string Title { get ; private set ; } = string . Empty ;
10
10
11
11
[ ObservableProperty ]
12
- public partial string Message { get ; set ; } = "This message uses a ViewModel binding" ;
12
+ public partial string Message { get ; private set ; } = string . Empty ;
13
13
14
14
public TaskCompletionSource < IPopupResult > ? PopupResultManager { get ; set ; }
15
+
16
+ void IQueryAttributable . ApplyQueryAttributes ( IDictionary < string , object > query )
17
+ {
18
+ Title = ( string ) query [ nameof ( Title ) ] ;
19
+ Message = ( string ) query [ nameof ( Message ) ] ;
20
+ }
15
21
}
Original file line number Diff line number Diff line change @@ -9,7 +9,12 @@ public partial class PopupsViewModel(IPopupService popupService) : BaseViewModel
9
9
[ RelayCommand ]
10
10
void OnCsharpBindingPopup ( )
11
11
{
12
- popupService . ShowPopup < CsharpBindingPopupViewModel > ( currentNavigation ) ;
12
+ var queryAttributes = new Dictionary < string , object >
13
+ {
14
+ [ nameof ( CsharpBindingPopupViewModel . Title ) ] = "C# Binding Popup" ,
15
+ [ nameof ( CsharpBindingPopupViewModel . Message ) ] = "This message uses a ViewModel binding that was set using IQueryAttributable"
16
+ } ;
17
+ popupService . ShowPopup < CsharpBindingPopupViewModel > ( Shell . Current , null , queryAttributes ) ;
13
18
}
14
19
15
20
[ RelayCommand ]
Original file line number Diff line number Diff line change 33
33
34
34
<Label Style =" {StaticResource Title}" Text =" Simple Popup" />
35
35
<BoxView Style =" {StaticResource Divider}" />
36
- <Label Style =" {StaticResource Content}" Text = " This is a platform specific popup with a .NET MAUI View being rendered. " />
36
+ <Label x : Name = " DescriptionLabel " Style =" {StaticResource Content}" HorizontalOptions = " Center " />
37
37
<Image Source =" shield.png"
38
38
Margin =" 0,10,0,10"
39
39
WidthRequest =" 30"
Original file line number Diff line number Diff line change 1
1
namespace CommunityToolkit . Maui . Sample . Views . Popups ;
2
2
3
- public partial class SimplePopup : ContentView
3
+ public partial class SimplePopup : ContentView , IQueryAttributable
4
4
{
5
5
public SimplePopup ( )
6
6
{
7
7
InitializeComponent ( ) ;
8
8
}
9
+
10
+ void IQueryAttributable . ApplyQueryAttributes ( IDictionary < string , object > query )
11
+ {
12
+ DescriptionLabel . Text = ( string ) query [ nameof ( DescriptionLabel ) ] ;
13
+ }
9
14
}
Original file line number Diff line number Diff line change 1
1
namespace CommunityToolkit . Maui . Core ;
2
2
3
3
/// <inheritdoc/>
4
- public interface IPopupResult < T > : IPopupResult
4
+ public interface IPopupResult < out TResult > : IPopupResult
5
5
{
6
6
/// <summary>
7
- /// PopupResult
7
+ /// The result returned when the popup is closed programmatically.
8
8
/// </summary>
9
- T ? Result { get ; }
9
+ /// <remarks>
10
+ /// Make sure to check the <see cref="IPopupResult.WasDismissedByTappingOutsideOfPopup"/> value to determine how the popup was closed.
11
+ /// This will always return <c>null</c> when <see cref="IPopupResult.WasDismissedByTappingOutsideOfPopup"/> is <c>true</c>.
12
+ /// </remarks>
13
+ TResult ? Result { get ; }
10
14
}
11
15
12
16
/// <summary>
13
- /// Represents the result of a popup.
17
+ /// Represents a result that can be returned when a popup is closed .
14
18
/// </summary>
19
+ /// <remarks>
20
+ /// Make sure to check the <see cref="IPopupResult.WasDismissedByTappingOutsideOfPopup"/> value to determine how the popup was closed.
21
+ /// </remarks>
15
22
public interface IPopupResult
16
23
{
17
24
/// <summary>
18
- /// True if Popup is closed by tapping outside the popup
25
+ /// Gets whether the popup was closed by tapping outside the popup.
19
26
/// </summary>
20
27
bool WasDismissedByTappingOutsideOfPopup { get ; }
21
28
}
Original file line number Diff line number Diff line change @@ -85,10 +85,10 @@ static void InitializeServicesAndSetMockApplication(out IServiceProvider service
85
85
#endregion
86
86
87
87
var mauiApp = appBuilder . Build ( ) ;
88
+ serviceProvider = mauiApp . Services ;
88
89
89
90
var application = ( MockApplication ) mauiApp . Services . GetRequiredService < IApplication > ( ) ;
90
91
application . AddWindow ( new Window { Page = page } ) ;
91
- serviceProvider = mauiApp . Services ;
92
92
93
93
IPlatformApplication . Current = application ;
94
94
You can’t perform that action at this time.
0 commit comments