Skip to content

Commit ab7c582

Browse files
authored
Open URLs in default browser (#1481)
Fixes #1480
1 parent 6813158 commit ab7c582

File tree

6 files changed

+37
-16
lines changed

6 files changed

+37
-16
lines changed

MainDemo.Wpf/Domain/DocumentationLink.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Configuration;
33
using System.Windows.Controls;
44
using System.Windows.Input;
5+
using MaterialDesignDemo.Domain;
56

67
namespace MaterialDesignColors.WpfExample.Domain
78
{
@@ -17,7 +18,7 @@ public DocumentationLink(DocumentationLinkType type, string url, string label)
1718
Url = url;
1819
Type = type;
1920
Open = new AnotherCommandImplementation(Execute);
20-
}
21+
}
2122

2223
public static DocumentationLink WikiLink(string page, string label)
2324
{
@@ -26,7 +27,7 @@ public static DocumentationLink WikiLink(string page, string label)
2627
}
2728

2829
public static DocumentationLink StyleLink(string nameChunk)
29-
{
30+
{
3031
return new DocumentationLink(
3132
DocumentationLinkType.StyleSource,
3233
$"{ConfigurationManager.AppSettings["GitHub"]}/blob/master/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.{nameChunk}.xaml",
@@ -78,21 +79,21 @@ public static DocumentationLink DemoPageLink<TDemoPage>(string label, string nam
7879

7980
return new DocumentationLink(
8081
DocumentationLinkType.DemoPageSource,
81-
$"{ConfigurationManager.AppSettings["GitHub"]}/blob/master/MainDemo.Wpf/{(string.IsNullOrWhiteSpace(nameSpace) ? "" : ("/" + nameSpace + "/" ))}{typeof(TDemoPage).Name}.{ext}",
82+
$"{ConfigurationManager.AppSettings["GitHub"]}/blob/master/MainDemo.Wpf/{(string.IsNullOrWhiteSpace(nameSpace) ? "" : ("/" + nameSpace + "/"))}{typeof(TDemoPage).Name}.{ext}",
8283
label ?? typeof(TDemoPage).Name);
8384
}
8485

8586
public string Label { get; }
8687

8788
public string Url { get; }
8889

89-
public DocumentationLinkType Type { get; }
90+
public DocumentationLinkType Type { get; }
9091

9192
public ICommand Open { get; }
9293

9394
private void Execute(object o)
9495
{
95-
System.Diagnostics.Process.Start(Url);
96+
Link.OpenInBrowser(Url);
9697
}
9798
}
9899
}

MainDemo.Wpf/Domain/Link.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System.Diagnostics;
2+
using System.Runtime.InteropServices;
3+
4+
namespace MaterialDesignDemo.Domain
5+
{
6+
public static class Link
7+
{
8+
public static void OpenInBrowser(string url)
9+
{
10+
//https://github.com/dotnet/corefx/issues/10361
11+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
12+
{
13+
url = url.Replace("&", "^&");
14+
Process.Start(new ProcessStartInfo("cmd", $"/c start {url}") { CreateNoWindow = true });
15+
}
16+
}
17+
}
18+
}

MainDemo.Wpf/Home.xaml.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Diagnostics;
33
using System.Windows;
44
using System.Windows.Controls;
5+
using MaterialDesignDemo.Domain;
56

67
namespace MaterialDesignColors.WpfExample
78
{
@@ -17,27 +18,27 @@ public Home()
1718

1819
private void GitHubButton_OnClick(object sender, RoutedEventArgs e)
1920
{
20-
Process.Start(ConfigurationManager.AppSettings["GitHub"]);
21+
Link.OpenInBrowser(ConfigurationManager.AppSettings["GitHub"]);
2122
}
2223

2324
private void TwitterButton_OnClick(object sender, RoutedEventArgs e)
2425
{
25-
Process.Start("https://twitter.com/James_Willock");
26+
Link.OpenInBrowser("https://twitter.com/James_Willock");
2627
}
2728

2829
private void ChatButton_OnClick(object sender, RoutedEventArgs e)
2930
{
30-
Process.Start("https://gitter.im/ButchersBoy/MaterialDesignInXamlToolkit");
31+
Link.OpenInBrowser("https://gitter.im/ButchersBoy/MaterialDesignInXamlToolkit");
3132
}
3233

3334
private void EmailButton_OnClick(object sender, RoutedEventArgs e)
3435
{
35-
Process.Start("mailto://[email protected]");
36+
Link.OpenInBrowser("mailto://[email protected]");
3637
}
3738

3839
private void DonateButton_OnClick(object sender, RoutedEventArgs e)
3940
{
40-
Process.Start("https://opencollective.com/materialdesigninxaml");
41+
Link.OpenInBrowser("https://opencollective.com/materialdesigninxaml");
4142
}
4243
}
4344
}

MainDemo.Wpf/IconPackViewModel.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Windows;
88
using System.Windows.Input;
99
using MaterialDesignColors.WpfExample.Domain;
10+
using MaterialDesignDemo.Domain;
1011
using MaterialDesignThemes.Wpf;
1112

1213
namespace MaterialDesignDemo
@@ -48,7 +49,7 @@ public IEnumerable<PackIconKind> Kinds
4849

4950
private void OpenDotCom(object obj)
5051
{
51-
Process.Start("https://materialdesignicons.com/");
52+
Link.OpenInBrowser("https://materialdesignicons.com/");
5253
}
5354

5455
private void Search(object obj)

MainDemo.Wpf/MenusAndToolBars.xaml.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
using System.Diagnostics;
2-
using System.Windows;
1+
using System.Windows;
32
using System.Windows.Controls;
3+
using MaterialDesignDemo.Domain;
44

55
namespace MaterialDesignColors.WpfExample
66
{
@@ -16,7 +16,7 @@ public MenusAndToolBars()
1616

1717
private void TwitterButton_OnClick(object sender, RoutedEventArgs e)
1818
{
19-
Process.Start("https://twitter.com/James_Willock");
19+
Link.OpenInBrowser("https://twitter.com/James_Willock");
2020
}
2121
}
2222
}

MainDemo.Wpf/TextFields.xaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
using System.Windows;
22
using System.Windows.Controls;
3-
using System.Windows.Documents;
43
using System.Windows.Navigation;
54
using MaterialDesignColors.WpfExample.Domain;
5+
using MaterialDesignDemo.Domain;
66

77
namespace MaterialDesignColors.WpfExample
88
{
@@ -23,7 +23,7 @@ private void UserControl_Loaded(object sender, RoutedEventArgs e)
2323

2424
private void Hyperlink_OnRequestNavigate(object sender, RequestNavigateEventArgs e)
2525
{
26-
System.Diagnostics.Process.Start(e.Uri.AbsoluteUri);
26+
Link.OpenInBrowser(e.Uri.AbsoluteUri);
2727
}
2828
}
2929
}

0 commit comments

Comments
 (0)