Skip to content

Commit b5936d2

Browse files
committed
created custom button exts
1 parent 48a76fc commit b5936d2

4 files changed

Lines changed: 89 additions & 10 deletions

File tree

.idea/.idea.CutCode/.idea/workspace.xml

Lines changed: 16 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CutCode.CrossPlatform/CutCode.CrossPlatform.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<Content Include="Assets\Images\logo.ico" />
2727
</ItemGroup>
2828
<ItemGroup>
29-
<PackageReference Include="Aura.UI" Version="0.1.5-dev-03" />
29+
<PackageReference Include="Aura.UI" Version="0.1.5-dev-04" />
3030
<PackageReference Include="Avalonia" Version="0.10.999-cibuild0017742-beta" />
3131
<PackageReference Include="Avalonia.Desktop" Version="0.10.999-cibuild0017742-beta" />
3232
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
using System;
2+
using System.Diagnostics;
3+
using System.Runtime.InteropServices;
4+
using Aura.UI.ExtensionProperties;
5+
using AuraUtilities;
6+
using Avalonia;
7+
using Avalonia.Controls;
8+
using Avalonia.Data;
9+
using Avalonia.Interactivity;
10+
11+
namespace CutCode.CrossPlatfrom.Helpers
12+
{
13+
public static class UrlUtils
14+
{
15+
public static void OpenUrl(string url)
16+
{
17+
if (url == null)
18+
return;
19+
ProcessStartInfo startInfo = new ProcessStartInfo();
20+
startInfo.RedirectStandardOutput = true;
21+
startInfo.RedirectStandardError = true;
22+
startInfo.UseShellExecute = false;
23+
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
24+
startInfo.CreateNoWindow = true;
25+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
26+
{
27+
startInfo.FileName = "powershell";
28+
startInfo.Arguments = "start \"" + url + "\"";
29+
Process.Start(startInfo);
30+
}
31+
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
32+
{
33+
startInfo.FileName = "xdg-open";
34+
startInfo.Arguments = " " + url;
35+
Process.Start(startInfo);
36+
}
37+
else
38+
{
39+
if (!RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
40+
return;
41+
startInfo.FileName = "open";
42+
startInfo.Arguments = url ?? "";
43+
Process.Start(startInfo);
44+
}
45+
}
46+
}
47+
48+
public class ButtonExts : AvaloniaObject
49+
{
50+
public static readonly AttachedProperty<string> UrlProperty = AvaloniaProperty.RegisterAttached<Aura.UI.ExtensionProperties.ButtonExts, Button, string>("Url");
51+
52+
public static string GetUrl(Button button) => button.GetValue<string>((StyledPropertyBase<string>) Aura.UI.ExtensionProperties.ButtonExts.UrlProperty);
53+
54+
public static void SetUrl(Button button, string url) => button.SetValue<string>((StyledPropertyBase<string>) Aura.UI.ExtensionProperties.ButtonExts.UrlProperty, url, BindingPriority.LocalValue);
55+
56+
static ButtonExts() => Aura.UI.ExtensionProperties.ButtonExts.UrlProperty.Changed.Subscribe<AvaloniaPropertyChangedEventArgs<string>>((Action<AvaloniaPropertyChangedEventArgs<string>>) (e1 =>
57+
{
58+
Button btn = e1.Sender as Button;
59+
if (btn == null)
60+
return;
61+
btn.Click += (EventHandler<RoutedEventArgs>) ((s, e2) =>
62+
{
63+
if (string.IsNullOrEmpty(Aura.UI.ExtensionProperties.ButtonExts.GetUrl(btn)))
64+
return;
65+
UrlUtils.OpenUrl(Aura.UI.ExtensionProperties.ButtonExts.GetUrl(btn));
66+
});
67+
}));
68+
}
69+
}

CutCode.CrossPlatform/Views/DeveloperCardView.axaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
44
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
55
xmlns:converters="using:CutCode.CrossPlatform.Converters"
6-
xmlns:exts="using:Aura.UI.ExtensionProperties"
76
xmlns:defconverters="clr-namespace:Avalonia.Markup.Xaml.Converters;assembly=Avalonia.Markup.Xaml"
7+
xmlns:helpers="clr-namespace:CutCode.CrossPlatfrom.Helpers"
88
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
99
x:Class="CutCode.CrossPlatform.Views.DeveloperCardView">
1010

@@ -40,7 +40,7 @@
4040
TextWrapping="Wrap"/>
4141
<StackPanel Orientation="Horizontal" Margin="-7,7,0,0">
4242
<Button
43-
exts:ButtonExts.Url="{Binding Twitter}"
43+
helpers:ButtonExts.Url="{Binding Twitter}"
4444
Background="Transparent"
4545
Width="30" Height="30">
4646
<Viewbox>
@@ -49,7 +49,7 @@
4949
</Viewbox>
5050
</Button>
5151
<Button
52-
exts:ButtonExts.Url="{Binding Github}"
52+
helpers:ButtonExts.Url="{Binding Github}"
5353
Background="Transparent"
5454
Width="30" Height="30">
5555
<Viewbox>

0 commit comments

Comments
 (0)