2
2
// The .NET Foundation licenses this file to you under the MIT license.
3
3
// See the LICENSE file in the project root for more information.
4
4
5
+ using System ;
6
+ using Microsoft . Toolkit . Uwp . UI . Controls ;
7
+ using Windows . System ;
5
8
using Windows . UI . Xaml ;
6
9
using Windows . UI . Xaml . Controls ;
7
10
@@ -10,8 +13,39 @@ namespace MvvmSampleUwp.Controls;
10
13
/// <summary>
11
14
/// A simple control that acts as a container for a documentation block.
12
15
/// </summary>
16
+ [ TemplatePart ( Name = "PART_MarkdownTextBlock" , Type = typeof ( MarkdownTextBlock ) ) ]
13
17
public sealed class DocumentationBlock : ContentControl
14
18
{
19
+ /// <summary>
20
+ /// The <see cref="MarkdownTextBlock"/> instance in use.
21
+ /// </summary>
22
+ private MarkdownTextBlock markdownTextBlock ;
23
+
24
+ /// <inheritdoc/>
25
+ protected override void OnApplyTemplate ( )
26
+ {
27
+ base . OnApplyTemplate ( ) ;
28
+
29
+ markdownTextBlock = ( MarkdownTextBlock ) GetTemplateChild ( "PART_MarkdownTextBlock" ) ;
30
+
31
+ markdownTextBlock . LinkClicked += MarkdownTextBlock_LinkClicked ;
32
+ }
33
+
34
+ /// <summary>
35
+ /// Handles a clicked link in a markdown block.
36
+ /// </summary>
37
+ /// <param name="sender">The source <see cref="MarkdownTextBlock"/> control.</param>
38
+ /// <param name="e">The input arguments.</param>
39
+ private void MarkdownTextBlock_LinkClicked ( object sender , LinkClickedEventArgs e )
40
+ {
41
+ if ( Uri . TryCreate ( e . Link , UriKind . Absolute , out Uri result ) ||
42
+ ( e . Link . StartsWith ( "/dotnet" ) &&
43
+ Uri . TryCreate ( $ "https://docs.microsoft.com{ e . Link } ", UriKind . Absolute , out result ) ) )
44
+ {
45
+ _ = Launcher . LaunchUriAsync ( result ) ;
46
+ }
47
+ }
48
+
15
49
/// <summary>
16
50
/// Gets or sets the <see cref="string"/> representing the text to display.
17
51
/// </summary>
0 commit comments