diff --git a/docs/maui/TOC.yml b/docs/maui/TOC.yml index 9dbb592e..2c295ba5 100644 --- a/docs/maui/TOC.yml +++ b/docs/maui/TOC.yml @@ -214,7 +214,7 @@ items: - name: "MediaElement" href: views/MediaElement.md - name: "Popup" - href: views/popup.md + href: views/Popup.md - name: SemanticOrderView href: views/semantic-order-view.md - name: C# Markup diff --git a/docs/maui/views/DrawingView.md b/docs/maui/views/DrawingView.md index d812fec0..94144fd8 100644 --- a/docs/maui/views/DrawingView.md +++ b/docs/maui/views/DrawingView.md @@ -100,13 +100,17 @@ var drawingView = new DrawingView Lines = new ObservableCollection(), DrawingLineCompletedCommand = new Command(async (line) => { - var stream = await line.GetImageStream(gestureImage.Width, gestureImage.Height, Colors.Gray.AsPaint()); + var cts = new CancellationTokenSource(TimeSpan.FromSeconds(5)); + + var stream = await line.GetImageStream(gestureImage.Width, gestureImage.Height, Colors.Gray.AsPaint(), cts.Token); gestureImage.Source = ImageSource.FromStream(() => stream); }) }; drawingView.OnDrawingLineCompleted += async (s, e) => { - var stream = await e.LastDrawingLine.GetImageStream(gestureImage.Width, gestureImage.Height, Colors.Gray.AsPaint()); + var cts = new CancellationTokenSource(TimeSpan.FromSeconds(5)); + + var stream = await e.LastDrawingLine.GetImageStream(gestureImage.Width, gestureImage.Height, Colors.Gray.AsPaint(), cts.Token); gestureImage.Source = ImageSource.FromStream(() => stream); }; ``` @@ -153,7 +157,9 @@ var drawingView = new DrawingView ShouldClearOnFinish = false, DrawingLineCompletedCommand = new Command(async (line) => { - var stream = await line.GetImageStream(gestureImage.Width, gestureImage.Height, Colors.Gray.AsPaint()); + var cts = new CancellationTokenSource(TimeSpan.FromSeconds(5)); + + var stream = await line.GetImageStream(gestureImage.Width, gestureImage.Height, Colors.Gray.AsPaint(), cts.Token); gestureImage.Source = ImageSource.FromStream(() => stream); }), LineColor = Colors.Red, @@ -162,19 +168,23 @@ var drawingView = new DrawingView }; drawingView.OnDrawingLineCompleted += async (s, e) => { - var stream = await e.LastDrawingLine.GetImageStream(gestureImage.Width, gestureImage.Height, Colors.Gray.AsPaint()); + var cts = new CancellationTokenSource(TimeSpan.FromSeconds(5)); + + var stream = await e.LastDrawingLine.GetImageStream(gestureImage.Width, gestureImage.Height, Colors.Gray.AsPaint(), cts.Token); gestureImage.Source = ImageSource.FromStream(() => stream); }; // get stream from lines collection +var cts = new CancellationTokenSource(TimeSpan.FromSeconds(5)); var lines = new List(); var stream1 = await DrawingView.GetImageStream( lines, new Size(gestureImage.Width, gestureImage.Height), - Colors.Black); + Colors.Black. + cts.Token); // get steam from the current DrawingView -var stream2 = await drawingView.GetImageStream(gestureImage.Width, gestureImage.Height); +var stream2 = await drawingView.GetImageStream(gestureImage.Width, gestureImage.Height, cts.Token); ``` ## Properties diff --git a/docs/maui/views/MediaElement.md b/docs/maui/views/MediaElement.md index 6d3307d4..29d6c5d7 100644 --- a/docs/maui/views/MediaElement.md +++ b/docs/maui/views/MediaElement.md @@ -341,7 +341,7 @@ To read more about handlers, please see the .NET MAUI documentation on [Handlers | Play | Starts playing the loaded media. | | Pause | Pauses playback of the current media. | | Stop | Stops playback and resets the position of the current media. | -| SeekTo | Takes a `TimeSpan` value to set the `Position` property to. | +| SeekTo | Takes a `TimeSpan` value to set the `Position` property to and takes a `CancellationToken` to cancel the `Task`. | ## Examples diff --git a/docs/maui/views/popup.md b/docs/maui/views/Popup.md similarity index 95% rename from docs/maui/views/popup.md rename to docs/maui/views/Popup.md index 3eae07dd..ff13b938 100644 --- a/docs/maui/views/popup.md +++ b/docs/maui/views/Popup.md @@ -113,7 +113,7 @@ public class MyViewModel : INotifyPropertyChanged For a more concrete example please refer to our sample application and the example in [`MultiplePopupViewModel`](https://github.com/CommunityToolkit/Maui/blob/main/samples/CommunityToolkit.Maui.Sample/ViewModels/Views/Popup/MultiplePopupViewModel.cs) -The `IPopupService` also provides methods to handle a result being returned from a Popup as covered in [Returning a result](./popup.md#returning-a-result). +The `IPopupService` also provides methods to handle a result being returned from a Popup as covered in [Returning a result](./Popup.md#returning-a-result). #### Passing data to a Popup view model @@ -165,7 +165,7 @@ There are 2 different ways that a `Popup` can be closed; programmatically or by In order to close a `Popup` a developer must call `Close` or `CloseAsync` on the `Popup` itself. This is typically performed by responding to a button press from a user. -If we enhance the previous XAML example by adding an ok `Button`: +We can enhance the previous XAML example by adding an **OK** `Button`: ```xml await CloseAsync(true); +async void OnYesButtonClicked(object? sender, EventArgs e) +{ + var cts = new CancellationTokenSource(TimeSpan.FromSeconds(5)); + await CloseAsync(true, cts.Token); +} -async void OnNoButtonClicked(object? sender, EventArgs e) => await CloseAsync(false); +async void OnNoButtonClicked(object? sender, EventArgs e) +{ + var cts = new CancellationTokenSource(TimeSpan.FromSeconds(5)); + await CloseAsync(false, cts.Token); +} ``` The `Close` method allows for an `object` value to be supplied, this will be the resulting return value. In order to await the result the `ShowPopupAsync` method must be used as follows: @@ -261,7 +271,7 @@ public class MyPage : ContentPage { var popup = new SimplePopup(); - var result = await this.ShowPopupAsync(popup); + var result = await this.ShowPopupAsync(popup, CancellationToken.None); if (result is bool boolResult) { diff --git a/docs/maui/views/index.md b/docs/maui/views/index.md index 43fe8738..5d0ea53d 100644 --- a/docs/maui/views/index.md +++ b/docs/maui/views/index.md @@ -25,5 +25,5 @@ The .NET MAUI Community Toolkit provides a collection of pre-built, reusable vie | [`LazyView`](LazyView.md) | The `LazyView` control allows you to delay the initialization of a View.| | [`Map (Windows)`](Map.md) | The `Map` control is a cross-platform view for displaying and annotating maps. The Windows implementation is available through the .NET MAUI Community Toolkit. | | [`MediaElement`](MediaElement.md) | The `MediaElement` is a view for playing multimedia such as audio and video. | -| [`Popup`](popup.md) | The `Popup` view allows developers to build their own custom UI and present it to their users. | +| [`Popup`](Popup.md) | The `Popup` view allows developers to build their own custom UI and present it to their users. | | [`SemanticOrderView`](semantic-order-view.md) | The `SemanticOrderView` provides the ability to control the order of VisualElements for screen readers and improve the Accessibility of an application. |