-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
r.sorokin
committed
Jun 21, 2022
0 parents
commit 6504f63
Showing
19 changed files
with
893 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<Application xmlns="https://github.com/avaloniaui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:local="using:HyperText.Avalonia.Example" | ||
xmlns:avalonia="clr-namespace:HyperText.Avalonia;assembly=HyperText.Avalonia" | ||
x:Class="HyperText.Avalonia.Example.App"> | ||
<Application.DataTemplates> | ||
<local:ViewLocator/> | ||
</Application.DataTemplates> | ||
|
||
<Application.Styles> | ||
<FluentTheme Mode="Light"/> | ||
|
||
|
||
</Application.Styles> | ||
</Application> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using Avalonia; | ||
using Avalonia.Controls.ApplicationLifetimes; | ||
using Avalonia.Markup.Xaml; | ||
using HyperText.Avalonia.Example.ViewModels; | ||
using HyperText.Avalonia.Example.Views; | ||
|
||
namespace HyperText.Avalonia.Example | ||
{ | ||
public partial class App : Application | ||
{ | ||
public override void Initialize() | ||
{ | ||
AvaloniaXamlLoader.Load(this); | ||
} | ||
|
||
public override void OnFrameworkInitializationCompleted() | ||
{ | ||
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) | ||
{ | ||
desktop.MainWindow = new MainWindow | ||
{ | ||
DataContext = new MainWindowViewModel(), | ||
}; | ||
} | ||
|
||
base.OnFrameworkInitializationCompleted(); | ||
} | ||
} | ||
} |
Binary file not shown.
33 changes: 33 additions & 0 deletions
33
HyperText.Avalonia.Example/HyperText.Avalonia.Example.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>WinExe</OutputType> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<!--Avalonia doesen't support TrimMode=link currently,but we are working on that https://github.com/AvaloniaUI/Avalonia/issues/6892 --> | ||
<TrimMode>copyused</TrimMode> | ||
<BuiltInComInteropSupport>true</BuiltInComInteropSupport> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Folder Include="Models\" /> | ||
<AvaloniaResource Include="Assets\**" /> | ||
<None Remove=".gitignore" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<!--This helps with theme dll-s trimming. | ||
If you will publish your application in self-contained mode with p:PublishTrimmed=true and it will use Fluent theme Default theme will be trimmed from the output and vice versa. | ||
https://github.com/AvaloniaUI/Avalonia/issues/5593 --> | ||
<TrimmableAssembly Include="Avalonia.Themes.Fluent" /> | ||
<TrimmableAssembly Include="Avalonia.Themes.Default" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Avalonia" Version="0.10.15" /> | ||
<PackageReference Include="Avalonia.Desktop" Version="0.10.15" /> | ||
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.--> | ||
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="0.10.15" /> | ||
<PackageReference Include="Avalonia.ReactiveUI" Version="0.10.15" /> | ||
<PackageReference Include="XamlNameReferenceGenerator" Version="1.3.4" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\HyperText.Avalonia\HyperText.Avalonia.csproj" /> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using Avalonia; | ||
using Avalonia.ReactiveUI; | ||
using System; | ||
|
||
namespace HyperText.Avalonia.Example | ||
{ | ||
class Program | ||
{ | ||
// Initialization code. Don't use any Avalonia, third-party APIs or any | ||
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized | ||
// yet and stuff might break. | ||
[STAThread] | ||
public static void Main(string[] args) => BuildAvaloniaApp() | ||
.StartWithClassicDesktopLifetime(args); | ||
|
||
// Avalonia configuration, don't remove; also used by visual designer. | ||
public static AppBuilder BuildAvaloniaApp() | ||
=> AppBuilder.Configure<App>() | ||
.UsePlatformDetect() | ||
.LogToTrace() | ||
.UseReactiveUI(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System; | ||
using Avalonia.Controls; | ||
using Avalonia.Controls.Templates; | ||
using HyperText.Avalonia.Example.ViewModels; | ||
|
||
namespace HyperText.Avalonia.Example | ||
{ | ||
public class ViewLocator : IDataTemplate | ||
{ | ||
public IControl Build(object data) | ||
{ | ||
var name = data.GetType().FullName!.Replace("ViewModel", "View"); | ||
var type = Type.GetType(name); | ||
|
||
if (type != null) | ||
{ | ||
return (Control)Activator.CreateInstance(type)!; | ||
} | ||
|
||
return new TextBlock { Text = "Not Found: " + name }; | ||
} | ||
|
||
public bool Match(object data) | ||
{ | ||
return data is ViewModelBase; | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
HyperText.Avalonia.Example/ViewModels/MainWindowViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System.Collections.Generic; | ||
using HyperText.Avalonia.Models; | ||
|
||
namespace HyperText.Avalonia.Example.ViewModels | ||
{ | ||
public class MainWindowViewModel : ViewModelBase | ||
{ | ||
public IEnumerable<HyperlinkContent> HyperlinkContentProvider => new[] | ||
{ | ||
new HyperlinkContent | ||
{ Alias = "dedede ", Url = "https://avaloniaui.net/docs/styles/styles" }, | ||
new HyperlinkContent { Alias = "edvyydebbvydebvyed" }, | ||
new HyperlinkContent { Url = "https://avaloniaui.net/docs/styles/styles" } | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using ReactiveUI; | ||
|
||
namespace HyperText.Avalonia.Example.ViewModels | ||
{ | ||
public class ViewModelBase : ReactiveObject | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<Window xmlns="https://github.com/avaloniaui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:vm="using:HyperText.Avalonia.Example.ViewModels" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:controls="clr-namespace:HyperText.Avalonia.Controls;assembly=HyperText.Avalonia" | ||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" | ||
x:Class="HyperText.Avalonia.Example.Views.MainWindow" | ||
Icon="/Assets/avalonia-logo.ico" | ||
Title="HyperText.Avalonia.Example"> | ||
|
||
<Design.DataContext> | ||
<vm:MainWindowViewModel /> | ||
</Design.DataContext> | ||
|
||
|
||
<Grid RowDefinitions="Auto,*"> | ||
<ItemsControl x:Name="myItems" Items="{Binding HyperlinkContentProvider}"> | ||
<ItemsControl.ItemsPanel> | ||
<ItemsPanelTemplate> | ||
<StackPanel Orientation="Horizontal" /> | ||
</ItemsPanelTemplate> | ||
</ItemsControl.ItemsPanel> | ||
<ItemsControl.ItemTemplate> | ||
<DataTemplate> | ||
<controls:Hyperlink Text="{Binding Alias}" Url="{Binding Url}" /> | ||
</DataTemplate> | ||
</ItemsControl.ItemTemplate> | ||
|
||
</ItemsControl> | ||
<TextBox Grid.Row="1">xcfsdfsd</TextBox> | ||
</Grid> | ||
</Window> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using Avalonia.Controls; | ||
|
||
namespace HyperText.Avalonia.Example.Views | ||
{ | ||
public partial class MainWindow : Window | ||
{ | ||
public MainWindow() | ||
{ | ||
InitializeComponent(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HyperText.Avalonia", "HyperText.Avalonia\HyperText.Avalonia.csproj", "{650FA614-AE11-4493-A209-FF83C0ADA91C}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HyperText.Avalonia.Example", "HyperText.Avalonia.Example\HyperText.Avalonia.Example.csproj", "{78920BF1-F9A2-444E-B007-AE80ED2EC61D}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{650FA614-AE11-4493-A209-FF83C0ADA91C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{650FA614-AE11-4493-A209-FF83C0ADA91C}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{650FA614-AE11-4493-A209-FF83C0ADA91C}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{650FA614-AE11-4493-A209-FF83C0ADA91C}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{78920BF1-F9A2-444E-B007-AE80ED2EC61D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{78920BF1-F9A2-444E-B007-AE80ED2EC61D}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{78920BF1-F9A2-444E-B007-AE80ED2EC61D}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{78920BF1-F9A2-444E-B007-AE80ED2EC61D}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using Avalonia; | ||
using Avalonia.Controls; | ||
using Avalonia.Input; | ||
using HyperText.Avalonia.Extensions; | ||
|
||
namespace HyperText.Avalonia.Controls | ||
{ | ||
public class Hyperlink : TextBlock | ||
{ | ||
public static readonly DirectProperty<Hyperlink, string> UrlProperty | ||
= AvaloniaProperty.RegisterDirect<Hyperlink, string>(nameof(Url), o => o.Url, (o, v) => o.Url = v); | ||
|
||
private string _url; | ||
|
||
public string Url | ||
{ | ||
get => _url; | ||
set => SetAndRaise(UrlProperty, ref _url, value); | ||
} | ||
|
||
protected override void OnPointerPressed(PointerPressedEventArgs e) | ||
{ | ||
base.OnPointerPressed(e); | ||
if (!string.IsNullOrEmpty(Url)) | ||
Url.OpenUrl(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace HyperText.Avalonia.Exceptions | ||
{ | ||
public class InvalidUrlException : Exception | ||
{ | ||
public InvalidUrlException(string message) : base(message) | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System.Diagnostics; | ||
using System.Runtime.InteropServices; | ||
using HyperText.Avalonia.Exceptions; | ||
|
||
namespace HyperText.Avalonia.Extensions | ||
{ | ||
public static class OpenUrlExtension | ||
{ | ||
private static bool IsValidUrl(string url) | ||
{ | ||
if (string.IsNullOrWhiteSpace(url)) return false; | ||
if (!Uri.IsWellFormedUriString(url, UriKind.Absolute)) return false; | ||
if (!Uri.TryCreate(url, UriKind.Absolute, out var tmp)) return false; | ||
return tmp.Scheme == Uri.UriSchemeHttp || tmp.Scheme == Uri.UriSchemeHttps; | ||
} | ||
|
||
public static void OpenUrl(this string url) | ||
{ | ||
if (!IsValidUrl(url)) throw new InvalidUrlException("invalid url: " + url); | ||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) | ||
{ | ||
//https://stackoverflow.com/a/2796367/241446 | ||
using var proc = new Process { StartInfo = { UseShellExecute = true, FileName = url } }; | ||
proc.Start(); | ||
|
||
return; | ||
} | ||
|
||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) | ||
{ | ||
Process.Start("x-www-browser", url); | ||
return; | ||
} | ||
|
||
if (!RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) throw new InvalidUrlException("invalid url: " + url); | ||
Process.Start("open", url); | ||
return; | ||
} | ||
} | ||
} |
Oops, something went wrong.