private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e) { if (this.NavigateUri != null) { SdkUIUtilities.OpenExternalUrl(this.NavigateUri); } }
// Event handler for HyperLink click event in a XAML element private static void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e) { if (sender is Hyperlink hyperlink && !string.IsNullOrWhiteSpace(hyperlink.NavigateUri?.AbsoluteUri)) { SdkUIUtilities.OpenExternalUrl(hyperlink.NavigateUri.AbsoluteUri); e.Handled = true; } }
internal void InlineLink_Click(object sender, RoutedEventArgs e) { ThreadHelper.ThrowIfNotOnUIThread(); if (!(sender is XamlDoc.Hyperlink hyperLink)) { return; } string uriString = null; if (hyperLink.Tag is string uriAsString) { uriString = uriAsString; } else if (hyperLink.Tag is Uri uri) { uriString = uri.ToString(); } if (!string.IsNullOrEmpty(uriString) && Uri.TryCreate(uriString, UriKind.RelativeOrAbsolute, out Uri _)) { SdkUIUtilities.OpenExternalUrl(uriString); } }
private void ErrorListInlineLink_Click(object sender, RoutedEventArgs e) { ThreadHelper.ThrowIfNotOnUIThread(); if (!(sender is Hyperlink hyperLink)) { return; } if (hyperLink.Tag is int id) { // The user clicked an in-line link with an integer target. Look for a Location object // whose Id property matches that integer. The spec says that might be _any_ Location // object under the current result. At present, we only support Location objects that // occur in Result.Locations or Result.RelatedLocations. So, for example, we don't // look in Result.CodeFlows or Result.Stacks. LocationModel location = this.Error.RelatedLocations. Concat(this.Error.Locations). FirstOrDefault(l => l.Id == id); if (location == null) { return; } // If a location is found, then we will show this error in the explorer window // by setting the navigated item to the error related to this error entry, // but... we will navigate the editor to the found location, which for example // may be a related location. if (this.Error.HasDetails) { var componentModel = (IComponentModel)Package.GetGlobalService(typeof(SComponentModel)); if (componentModel != null) { ISarifErrorListEventSelectionService sarifSelectionService = componentModel.GetService <ISarifErrorListEventSelectionService>(); if (sarifSelectionService != null) { sarifSelectionService.NavigatedItem = this.Error; } } } location.NavigateTo(usePreviewPane: false, moveFocusToCaretLocation: true); } // This is super dangerous! We are launching URIs for SARIF logs // that can point to anything. // https://github.com/microsoft/sarif-visualstudio-extension/issues/171 else { string uriString = null; if (hyperLink.Tag is string uriAsString) { uriString = uriAsString; } else if (hyperLink.Tag is Uri uri) { uriString = uri.ToString(); } SdkUIUtilities.OpenExternalUrl(uriString); } }