Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Orc.Controls.Example/Views/LinkLabel.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<StackPanel Orientation="Horizontal" VerticalAlignment="Top" Margin="5" >
<TextBlock Text="LinkLabel" VerticalAlignment="Center" Width="160" />
<orccontrols:LinkLabel Content="Action" ToolTip="Action" Command="{Binding DefaultAction}"
HoverForeground="Orange" Url="http://catelproject.com"
HoverForeground="Orange" Url="catelproject.com"
ClickBehavior="OpenUrlInBrowser"/>
</StackPanel>
</catel:UserControl>
32 changes: 28 additions & 4 deletions src/Orc.Controls/Controls/LinkLabel/LinkLabel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public IInputElement? CommandTarget
/// <summary>
/// ClickEvent
/// </summary>
[Category("Behavior")]
[Category("Behavior")]
public static readonly RoutedEvent? ClickEvent;

/// <summary>
Expand All @@ -214,7 +214,7 @@ public event RoutedEventHandler? Click
/// <summary>
/// RequestNavigateEvent
/// </summary>
[Category("Behavior")]
[Category("Behavior")]
public static readonly RoutedEvent? RequestNavigateEvent;

/// <summary>
Expand Down Expand Up @@ -339,8 +339,32 @@ private static void OpenBrowserBehaviorImpl(object sender, RoutedEventArgs args)
return;
}

var destinationUrl = hyperlinkSender?.NavigateUri ?? linklabelSender?.Url;
if (destinationUrl is null || string.IsNullOrEmpty(destinationUrl.ToString()))
var uri = linklabelSender?.Url;
if (uri is null)
{
return;
}

if (!uri.IsAbsoluteUri || !(uri.Scheme.StartsWith("http", StringComparison.OrdinalIgnoreCase)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uri.Scheme.StartsWith("http", StringComparison.OrdinalIgnoreCase) || uri.Scheme.StartsWith("https", StringComparison.OrdinalIgnoreCase) === uri.Scheme.StartsWith("http", StringComparison.OrdinalIgnoreCase)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Catel even has StartsWithIgnoreCase and StartsWithAnyIgnoreCase

|| uri.Scheme.StartsWith("https", StringComparison.OrdinalIgnoreCase)))
{
string modifiedUriString;
if (uri.IsAbsoluteUri)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe there is a way not to check it twice

{
modifiedUriString = $"https://{uri}";
}
else
{
var relativePart = uri.GetComponents(UriComponents.PathAndQuery | UriComponents.Fragment,
UriFormat.UriEscaped);
modifiedUriString = $"https://{relativePart}";
}

uri = new Uri(modifiedUriString);
}

var destinationUrl = hyperlinkSender?.NavigateUri ?? uri;
if (string.IsNullOrEmpty(destinationUrl.ToString()))
{
return;
}
Expand Down