fajiao
2 years ago
12 changed files with 87 additions and 64 deletions
@ -1,29 +1,26 @@ |
|||||
using Avalonia; |
using Avalonia; |
||||
using Avalonia.Controls.ApplicationLifetimes; |
using Avalonia.Controls.ApplicationLifetimes; |
||||
using Avalonia.Markup.Xaml; |
using Avalonia.Markup.Xaml; |
||||
using JiLinApp.ViewModels; |
using JiLinApp.Pages.Main; |
||||
using JiLinApp.Views; |
|
||||
|
|
||||
namespace JiLinApp |
namespace JiLinApp; |
||||
|
|
||||
|
public partial class App : Application |
||||
{ |
{ |
||||
public partial class App : Application |
public override void Initialize() |
||||
{ |
{ |
||||
public override void Initialize() |
AvaloniaXamlLoader.Load(this); |
||||
{ |
} |
||||
AvaloniaXamlLoader.Load(this); |
|
||||
} |
|
||||
|
|
||||
public override void OnFrameworkInitializationCompleted() |
public override void OnFrameworkInitializationCompleted() |
||||
|
{ |
||||
|
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) |
||||
{ |
{ |
||||
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) |
desktop.MainWindow = new MainWindow |
||||
{ |
{ |
||||
desktop.MainWindow = new MainWindow |
DataContext = new MainWindowViewModel(), |
||||
{ |
}; |
||||
DataContext = new MainWindowViewModel(), |
|
||||
}; |
|
||||
} |
|
||||
|
|
||||
base.OnFrameworkInitializationCompleted(); |
|
||||
} |
} |
||||
|
base.OnFrameworkInitializationCompleted(); |
||||
} |
} |
||||
} |
} |
Binary file not shown.
@ -0,0 +1,17 @@ |
|||||
|
using Avalonia.Controls; |
||||
|
using Avalonia.Platform; |
||||
|
using System; |
||||
|
|
||||
|
namespace JiLinApp.Core.Avalonia; |
||||
|
|
||||
|
public class NativeHost : NativeControlHost |
||||
|
{ |
||||
|
public IntPtr Handle { get; set; } |
||||
|
|
||||
|
protected override IPlatformHandle CreateNativeControlCore(IPlatformHandle parent) |
||||
|
{ |
||||
|
IPlatformHandle? pfHandle = base.CreateNativeControlCore(parent); |
||||
|
Handle = pfHandle.Handle; |
||||
|
return pfHandle; |
||||
|
} |
||||
|
} |
@ -0,0 +1,7 @@ |
|||||
|
using ReactiveUI; |
||||
|
|
||||
|
namespace JiLinApp.Core.Avalonia; |
||||
|
|
||||
|
public class ViewModelBase : ReactiveObject |
||||
|
{ |
||||
|
} |
@ -1,10 +1,10 @@ |
|||||
<Window xmlns="https://github.com/avaloniaui" |
<Window xmlns="https://github.com/avaloniaui" |
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
||||
xmlns:vm="using:JiLinApp.ViewModels" |
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" |
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" |
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" |
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" |
||||
|
xmlns:vm="using:JiLinApp.Pages.Main" |
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" |
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" |
||||
x:Class="JiLinApp.Views.MainWindow" |
x:Class="JiLinApp.Pages.Main.MainWindow" |
||||
x:DataType="vm:MainWindowViewModel" |
x:DataType="vm:MainWindowViewModel" |
||||
Icon="/Assets/avalonia-logo.ico" |
Icon="/Assets/avalonia-logo.ico" |
||||
Title="JiLinApp"> |
Title="JiLinApp"> |
@ -0,0 +1,11 @@ |
|||||
|
using Avalonia.Controls; |
||||
|
|
||||
|
namespace JiLinApp.Pages.Main; |
||||
|
|
||||
|
public partial class MainWindow : Window |
||||
|
{ |
||||
|
public MainWindow() |
||||
|
{ |
||||
|
InitializeComponent(); |
||||
|
} |
||||
|
} |
@ -0,0 +1,8 @@ |
|||||
|
using JiLinApp.Core.Avalonia; |
||||
|
|
||||
|
namespace JiLinApp.Pages.Main; |
||||
|
|
||||
|
public class MainWindowViewModel : ViewModelBase |
||||
|
{ |
||||
|
public string Greeting => "Welcome to Avalonia!"; |
||||
|
} |
@ -1,24 +1,35 @@ |
|||||
using Avalonia; |
using Avalonia; |
||||
|
using Avalonia.Media; |
||||
using Avalonia.ReactiveUI; |
using Avalonia.ReactiveUI; |
||||
using System; |
using System; |
||||
|
|
||||
namespace JiLinApp |
namespace JiLinApp; |
||||
|
|
||||
|
internal class Program |
||||
{ |
{ |
||||
internal 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
|
||||
// Initialization code. Don't use any Avalonia, third-party APIs or any
|
// yet and stuff might break.
|
||||
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
|
[STAThread] |
||||
// yet and stuff might break.
|
public static void Main(string[] args) => BuildAvaloniaApp() |
||||
[STAThread] |
.StartWithClassicDesktopLifetime(args); |
||||
public static void Main(string[] args) => BuildAvaloniaApp() |
|
||||
.StartWithClassicDesktopLifetime(args); |
|
||||
|
|
||||
// Avalonia configuration, don't remove; also used by visual designer.
|
// Avalonia configuration, don't remove; also used by visual designer.
|
||||
public static AppBuilder BuildAvaloniaApp() |
public static AppBuilder BuildAvaloniaApp() |
||||
=> AppBuilder.Configure<App>() |
=> AppBuilder.Configure<App>() |
||||
.UsePlatformDetect() |
.UsePlatformDetect() |
||||
.WithInterFont() |
.WithInterFont() |
||||
.LogToTrace() |
.LogToTrace() |
||||
.UseReactiveUI(); |
.UseReactiveUI() |
||||
} |
.With(new FontManagerOptions |
||||
|
{ |
||||
|
DefaultFamilyName = "avares://JiLinApp/Assets/Fonts/msyh.ttf#Microsoft YaHei", |
||||
|
FontFallbacks = new[] |
||||
|
{ |
||||
|
new FontFallback |
||||
|
{ |
||||
|
FontFamily = new FontFamily("avares://JiLinApp/Assets/Fonts/msyh.ttf#Microsoft YaHei") |
||||
|
} |
||||
|
} |
||||
|
}); |
||||
} |
} |
@ -1,7 +0,0 @@ |
|||||
namespace JiLinApp.ViewModels |
|
||||
{ |
|
||||
public class MainWindowViewModel : ViewModelBase |
|
||||
{ |
|
||||
public string Greeting => "Welcome to Avalonia!"; |
|
||||
} |
|
||||
} |
|
@ -1,8 +0,0 @@ |
|||||
using ReactiveUI; |
|
||||
|
|
||||
namespace JiLinApp.ViewModels |
|
||||
{ |
|
||||
public class ViewModelBase : ReactiveObject |
|
||||
{ |
|
||||
} |
|
||||
} |
|
@ -1,12 +0,0 @@ |
|||||
using Avalonia.Controls; |
|
||||
|
|
||||
namespace JiLinApp.Views |
|
||||
{ |
|
||||
public partial class MainWindow : Window |
|
||||
{ |
|
||||
public MainWindow() |
|
||||
{ |
|
||||
InitializeComponent(); |
|
||||
} |
|
||||
} |
|
||||
} |
|
Loading…
Reference in new issue