diff --git a/AIDevGallery/Controls/Markdown/TextElements/MyHyperlink.cs b/AIDevGallery/Controls/Markdown/TextElements/MyHyperlink.cs index f1ecd7c8..4888d9d3 100644 --- a/AIDevGallery/Controls/Markdown/TextElements/MyHyperlink.cs +++ b/AIDevGallery/Controls/Markdown/TextElements/MyHyperlink.cs @@ -1,9 +1,9 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. - using HtmlAgilityPack; using Markdig.Syntax.Inlines; using Microsoft.UI.Xaml.Documents; +using System; using Windows.Foundation; namespace CommunityToolkit.Labs.WinUI.MarkdownTextBlock.TextElements; @@ -52,15 +52,19 @@ public MyHyperlink(HtmlNode htmlNode, string? baseUrl) public void AddChild(IAddChild child) { - if (child.TextElement is Microsoft.UI.Xaml.Documents.Inline inlineChild) + // Hyperlink cannot contain InlineUIContainer - this is a WinUI limitation + if (child.TextElement is not Microsoft.UI.Xaml.Documents.Inline inlineChild || inlineChild is InlineUIContainer) + { + return; + } + + try + { + _hyperlink.Inlines.Add(inlineChild); + } + catch (Exception ex) { - try - { - _hyperlink.Inlines.Add(inlineChild); - } - catch - { - } + System.Diagnostics.Debug.WriteLine($"Exception when adding {inlineChild.GetType().Name}: {ex.GetType().Name} - {ex.Message}"); } } } \ No newline at end of file diff --git a/AIDevGallery/Pages/Models/ModelPage.xaml b/AIDevGallery/Pages/Models/ModelPage.xaml index 60ed7c2a..4cb8a80b 100644 --- a/AIDevGallery/Pages/Models/ModelPage.xaml +++ b/AIDevGallery/Pages/Models/ModelPage.xaml @@ -73,33 +73,28 @@ - - - - - - - - - - - - + Margin="0,8,0,0" + ColumnSpacing="16" + RowSpacing="16"> + + + + + + + + + + - @@ -228,7 +222,6 @@ - diff --git a/AIDevGallery/Pages/Models/ModelPage.xaml.cs b/AIDevGallery/Pages/Models/ModelPage.xaml.cs index 18d340cd..d368f340 100644 --- a/AIDevGallery/Pages/Models/ModelPage.xaml.cs +++ b/AIDevGallery/Pages/Models/ModelPage.xaml.cs @@ -249,28 +249,40 @@ private void ToolkitActionFlyoutItem_Click(object sender, RoutedEventArgs e) (AIToolkitAction action, ModelDetails modelDetails) = ((AIToolkitAction, ModelDetails))actionFlyoutItem.Tag; string toolkitDeeplink = modelDetails.CreateAiToolkitDeeplink(action); - bool wasDeeplinkSuccesful = true; - try + _ = Task.Run(() => { - Process.Start(new ProcessStartInfo() + bool wasDeeplinkSuccesful = true; + try { - FileName = toolkitDeeplink, - UseShellExecute = true - }); - } - catch - { - Process.Start(new ProcessStartInfo() + Process.Start(new ProcessStartInfo() + { + FileName = toolkitDeeplink, + UseShellExecute = true + }); + } + catch { - FileName = "https://learn.microsoft.com/en-us/windows/ai/toolkit/", - UseShellExecute = true - }); - wasDeeplinkSuccesful = false; - } - finally - { - AIToolkitActionClickedEvent.Log(AIToolkitHelper.AIToolkitActionInfos[action].QueryName, modelDetails.Name, wasDeeplinkSuccesful); - } + try + { + Process.Start(new ProcessStartInfo() + { + FileName = "https://learn.microsoft.com/en-us/windows/ai/toolkit/", + UseShellExecute = true + }); + } + catch (Exception ex) + { + // Log the failure to open the fallback URL for diagnostics, but do not surface it to the user. + Debug.WriteLine($"Failed to open AI Toolkit fallback URL: {ex}"); + } + + wasDeeplinkSuccesful = false; + } + finally + { + AIToolkitActionClickedEvent.Log(AIToolkitHelper.AIToolkitActionInfos[action].QueryName, modelDetails.Name, wasDeeplinkSuccesful); + } + }); } } @@ -312,22 +324,28 @@ private void MarkdownTextBlock_OnLinkClicked(object sender, CommunityToolkit.Lab return; } - try + _ = Task.Run(() => { - var psi = new ProcessStartInfo + try { - FileName = uri.AbsoluteUri, - UseShellExecute = true - }; - Process.Start(psi); - } - catch (Exception ex) when (ex is Win32Exception - || ex is InvalidOperationException - || ex is PlatformNotSupportedException) - { - ModelDetailsLinkClickedEvent.Log($"OpenFailed: {uri} | {ex.GetType().Name}: {ex.Message}"); - ShowDialog(message: errorMessage); - } + var psi = new ProcessStartInfo + { + FileName = uri.AbsoluteUri, + UseShellExecute = true + }; + Process.Start(psi); + } + catch (Exception ex) when (ex is Win32Exception + || ex is InvalidOperationException + || ex is PlatformNotSupportedException) + { + ModelDetailsLinkClickedEvent.Log($"OpenFailed: {uri} | {ex.GetType().Name}: {ex.Message}"); + DispatcherQueue.TryEnqueue(() => + { + ShowDialog(message: errorMessage); + }); + } + }); } private async void ShowDialog(string? message)