commit e1e3f1d410e74c9383ef259942e78cfd344867ec Author: zxl Date: Tue Jan 21 14:26:54 2025 +0800 add:初始化仓库; 当前具备功能 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2690e5a --- /dev/null +++ b/.gitignore @@ -0,0 +1,71 @@ +# This .gitignore file should be placed at the root of your Unity project directory +# +# Get latest from https://github.com/github/gitignore/blob/main/Unity.gitignore +# +/[Ll]ibrary/ +/[Tt]emp/ +/[Oo]bj/ +/[Bb]uild/ +/[Bb]uilds/ +/[Ll]ogs/ +/[Uu]ser[Ss]ettings/ +/[Pp]rojectSettings/ +/[Pp]ackages/ + +# MemoryCaptures can get excessive in size. +# They also could contain extremely sensitive data +/[Mm]emoryCaptures/ + +# Recordings can get excessive in size +/[Rr]ecordings/ + +# Uncomment this line if you wish to ignore the asset store tools plugin +# /[Aa]ssets/AssetStoreTools* + +# Autogenerated Jetbrains Rider plugin +/[Aa]ssets/Plugins/Editor/JetBrains* + +# Visual Studio cache directory +.vs/ +.idea/ + +# Gradle cache directory +.gradle/ + +# Autogenerated VS/MD/Consulo solution and project files +ExportedObj/ +.consulo/ +*.csproj +*.unityproj +*.sln +*.suo +*.tmp +*.user +*.userprefs +*.pidb +*.booproj +*.svd +*.pdb +*.mdb +*.opendb +*.VC.db + +# Unity3D generated meta files + + +# Unity3D generated file on crash reports +sysinfo.txt + +# Builds + + +# Crashlytics generated file +crashlytics-build.properties + +# Packed Addressables + + +# 管理界面项目资产文件不跟踪 + +/ZTools/bin +/ZTools/obj diff --git a/ZTools/App.axaml b/ZTools/App.axaml new file mode 100644 index 0000000..2136345 --- /dev/null +++ b/ZTools/App.axaml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ZTools/App.axaml.cs b/ZTools/App.axaml.cs new file mode 100644 index 0000000..02edcee --- /dev/null +++ b/ZTools/App.axaml.cs @@ -0,0 +1,47 @@ +using Avalonia; +using Avalonia.Controls.ApplicationLifetimes; +using Avalonia.Data.Core; +using Avalonia.Data.Core.Plugins; +using System.Linq; +using Avalonia.Markup.Xaml; +using ZTools.ViewModels; +using ZTools.Views; + +namespace ZTools; + +public partial class App : Application +{ + public override void Initialize() + { + AvaloniaXamlLoader.Load(this); + } + + public override void OnFrameworkInitializationCompleted() + { + if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) + { + // Avoid duplicate validations from both Avalonia and the CommunityToolkit. + // More info: https://docs.avaloniaui.net/docs/guides/development-guides/data-validation#manage-validationplugins + DisableAvaloniaDataAnnotationValidation(); + desktop.MainWindow = new MainWindow + { + DataContext = new MainWindowViewModel(), + }; + } + + base.OnFrameworkInitializationCompleted(); + } + + private void DisableAvaloniaDataAnnotationValidation() + { + // Get an array of plugins to remove + var dataValidationPluginsToRemove = + BindingPlugins.DataValidators.OfType().ToArray(); + + // remove each entry found + foreach (var plugin in dataValidationPluginsToRemove) + { + BindingPlugins.DataValidators.Remove(plugin); + } + } +} \ No newline at end of file diff --git a/ZTools/Assets/Icon.axaml b/ZTools/Assets/Icon.axaml new file mode 100644 index 0000000..c7e5c7a --- /dev/null +++ b/ZTools/Assets/Icon.axaml @@ -0,0 +1,24 @@ + + + + + + + + + + \ No newline at end of file diff --git a/ZTools/Assets/Menu/个人.png b/ZTools/Assets/Menu/个人.png new file mode 100644 index 0000000..d95eb4e Binary files /dev/null and b/ZTools/Assets/Menu/个人.png differ diff --git a/ZTools/Assets/Menu/其他.png b/ZTools/Assets/Menu/其他.png new file mode 100644 index 0000000..63b8cc3 Binary files /dev/null and b/ZTools/Assets/Menu/其他.png differ diff --git a/ZTools/Assets/Menu/功能.png b/ZTools/Assets/Menu/功能.png new file mode 100644 index 0000000..482bb4c Binary files /dev/null and b/ZTools/Assets/Menu/功能.png differ diff --git a/ZTools/Assets/Menu/消息.png b/ZTools/Assets/Menu/消息.png new file mode 100644 index 0000000..42c6909 Binary files /dev/null and b/ZTools/Assets/Menu/消息.png differ diff --git a/ZTools/Assets/Menu/设置.png b/ZTools/Assets/Menu/设置.png new file mode 100644 index 0000000..1d1c2ba Binary files /dev/null and b/ZTools/Assets/Menu/设置.png differ diff --git a/ZTools/Assets/Menu/首页.png b/ZTools/Assets/Menu/首页.png new file mode 100644 index 0000000..1671a51 Binary files /dev/null and b/ZTools/Assets/Menu/首页.png differ diff --git a/ZTools/Assets/avalonia-logo.ico b/ZTools/Assets/avalonia-logo.ico new file mode 100644 index 0000000..da8d49f Binary files /dev/null and b/ZTools/Assets/avalonia-logo.ico differ diff --git a/ZTools/Assets/对.png b/ZTools/Assets/对.png new file mode 100644 index 0000000..097b4ed Binary files /dev/null and b/ZTools/Assets/对.png differ diff --git a/ZTools/Assets/对勾.png b/ZTools/Assets/对勾.png new file mode 100644 index 0000000..86d2ea1 Binary files /dev/null and b/ZTools/Assets/对勾.png differ diff --git a/ZTools/Models/Log.cs b/ZTools/Models/Log.cs new file mode 100644 index 0000000..411815e --- /dev/null +++ b/ZTools/Models/Log.cs @@ -0,0 +1,62 @@ +using System; +using System.Text; + +namespace ZTools; + +public enum LogLevel +{ + Error, + Warning, + Info, + Debug, +} + +public static class Log +{ + private static StringBuilder _logBuilder; + private static StringBuilder _tmp; + + internal static StringBuilder LogBuilder => _logBuilder; + public delegate void LogDelegate(string msg); + public static LogDelegate LogCallback; + + static Log() + { + _logBuilder = new StringBuilder(); + _tmp = new StringBuilder(); + } + + public static void Debug(object message) + { + Write(message, LogLevel.Debug); + } + + public static void Info(object message) + { + Write(message, LogLevel.Info); + } + + public static void Error(object message) + { + Write(message, LogLevel.Error); + } + + public static void Warning(object message) + { + Write(message, LogLevel.Warning); + } + + static void Write(object message, LogLevel level = LogLevel.Debug) + { + // var bytes = Encoding.UTF8.GetBytes(message.ToString() ?? string.Empty); + // var s = Encoding.UTF8.GetString(bytes); + + _tmp.Clear(); + _tmp.Append($"[{DateTime.Now:yyyy-MM-dd HH:mm:ss.fff}] {level}: {message}"); + + var format = _tmp.ToString(); + _logBuilder.AppendLine(format); + Console.WriteLine(format); + LogCallback?.Invoke(format); + } +} \ No newline at end of file diff --git a/ZTools/Models/MenuButtonItem.cs b/ZTools/Models/MenuButtonItem.cs new file mode 100644 index 0000000..01fb2f8 --- /dev/null +++ b/ZTools/Models/MenuButtonItem.cs @@ -0,0 +1,21 @@ +using System.Windows.Input; +using Avalonia.Media.Imaging; +using ZTools.ViewModels; + +namespace ZTools.Models; + +public class MenuButtonItem +{ + public Bitmap Icon { get; set; } + public string Content { get; set; } + public ICommand CommandEvent { get; set; } + public PageViewModelBase PageView { get; set; } + + public MenuButtonItem(Bitmap icon, string content, ICommand commandEvent, PageViewModelBase pageView) + { + Icon = icon; + Content = content; + CommandEvent = commandEvent; + PageView = pageView; + } +} \ No newline at end of file diff --git a/ZTools/Program.cs b/ZTools/Program.cs new file mode 100644 index 0000000..649d669 --- /dev/null +++ b/ZTools/Program.cs @@ -0,0 +1,21 @@ +using Avalonia; +using System; + +namespace ZTools; + +sealed 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() + .UsePlatformDetect() + .WithInterFont() + .LogToTrace(); +} \ No newline at end of file diff --git a/ZTools/Styles/SettingStyles.axaml b/ZTools/Styles/SettingStyles.axaml new file mode 100644 index 0000000..177aef6 --- /dev/null +++ b/ZTools/Styles/SettingStyles.axaml @@ -0,0 +1,16 @@ + + + + + + + + + + \ No newline at end of file diff --git a/ZTools/ViewLocator.cs b/ZTools/ViewLocator.cs new file mode 100644 index 0000000..abf296b --- /dev/null +++ b/ZTools/ViewLocator.cs @@ -0,0 +1,30 @@ +using System; +using Avalonia.Controls; +using Avalonia.Controls.Templates; +using ZTools.ViewModels; + +namespace ZTools; + +public class ViewLocator : IDataTemplate +{ + public Control? Build(object? param) + { + if (param is null) + return null; + + var name = param.GetType().FullName!.Replace("ViewModel", "View", StringComparison.Ordinal); + 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; + } +} \ No newline at end of file diff --git a/ZTools/ViewModels/MainWindowViewModel.cs b/ZTools/ViewModels/MainWindowViewModel.cs new file mode 100644 index 0000000..647dc63 --- /dev/null +++ b/ZTools/ViewModels/MainWindowViewModel.cs @@ -0,0 +1,93 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Windows.Input; +using Avalonia.Media; +using Avalonia.Media.Imaging; +using Avalonia.Platform; +using CommunityToolkit.Mvvm.ComponentModel; +using ZTools.Models; +using ZTools.Views; + +namespace ZTools.ViewModels; + +public partial class MainWindowItem : ObservableObject +{ + private string itemIconName; + [ObservableProperty] private Bitmap itemIcon; + [ObservableProperty] private string itemName; + + public MainWindowItem(string itemIcon, string itemName) + { + this.itemIconName = itemIcon; + var uri = itemIconName; + var bitmap = new Bitmap(AssetLoader.Open(new Uri(uri))); + this.itemIcon = bitmap; + this.itemName = itemName; + } +} + +public partial class MainWindowViewModel : ViewModelBase +{ + [ObservableProperty] + private ObservableCollection _menuItems = new ObservableCollection() + { + new MainWindowItem("avares://ZTools/Assets/Menu/个人.png","个人"), + new MainWindowItem("avares://ZTools/Assets/Menu/首页.png","首页"), + new MainWindowItem("avares://ZTools/Assets/Menu/消息.png","消息"), + new MainWindowItem("avares://ZTools/Assets/Menu/功能.png","功能"), + new MainWindowItem("avares://ZTools/Assets/Menu/其他.png","其他"), + }; + private MainWindowItem selectedMenuItem; + public MainWindowItem SelectedMenuItem + { + get => selectedMenuItem; + set + { + selectedMenuItem = value; + // this.RaiseAndSetIfChanged(ref selectedMenuItem, value); + OnSelectedItemChanged(); + } + } + private void OnSelectedItemChanged() + { + if (selectedMenuItem!= null) + { + Log.Debug($"Selected item in ViewModel: {selectedMenuItem.ItemName}"); + switch (selectedMenuItem.ItemName) + { + case "个人": + new SettingWindow().Show(); + break; + case "首页": + new SettingWindow().Show(); + break; + case "消息": + new SettingWindow().Show(); + break; + case "功能": + new SettingWindow().Show(); + break; + case "其他": + new SettingWindow().Show(); + break; + case "设置": + new SettingWindow().Show(); + break; + default: + throw new NullReferenceException(); + break; + } + } + else + { + Log.Debug("No item selected in ViewModel"); + } + } + + [ObservableProperty] + private ObservableCollection _leftDownItems = new ObservableCollection() + { + new MainWindowItem("avares://ZTools/Assets/Menu/设置.png","设置"), + }; +} \ No newline at end of file diff --git a/ZTools/ViewModels/Page/FeaturePageViewModel.cs b/ZTools/ViewModels/Page/FeaturePageViewModel.cs new file mode 100644 index 0000000..c0bc0e7 --- /dev/null +++ b/ZTools/ViewModels/Page/FeaturePageViewModel.cs @@ -0,0 +1,6 @@ +namespace ZTools.ViewModels; + +public class FeaturePageViewModel: PageViewModelBase +{ + +} \ No newline at end of file diff --git a/ZTools/ViewModels/Page/LogViewModel.cs b/ZTools/ViewModels/Page/LogViewModel.cs new file mode 100644 index 0000000..b37c073 --- /dev/null +++ b/ZTools/ViewModels/Page/LogViewModel.cs @@ -0,0 +1,26 @@ +using System.Collections.ObjectModel; +using Avalonia.Controls; +using CommunityToolkit.Mvvm.ComponentModel; +using ZTools.Models; + +namespace ZTools.ViewModels; + +public partial class LogItem +{ + public string Message { get; set; } = string.Empty; +} + +public partial class LogViewModel : PageViewModelBase +{ + [ObservableProperty] private ObservableCollection _myLogs = new ObservableCollection(); + + public LogViewModel() + { + Log.LogCallback += UpdateLog; + } + + private void UpdateLog(string obj) + { + MyLogs.Add(new LogItem() { Message = obj }); + } +} \ No newline at end of file diff --git a/ZTools/ViewModels/Page/PageViewModelBase.cs b/ZTools/ViewModels/Page/PageViewModelBase.cs new file mode 100644 index 0000000..84c3044 --- /dev/null +++ b/ZTools/ViewModels/Page/PageViewModelBase.cs @@ -0,0 +1,6 @@ +namespace ZTools.ViewModels; + +public abstract class PageViewModelBase : ViewModelBase +{ + +} \ No newline at end of file diff --git a/ZTools/ViewModels/Page/SettingViewModel.cs b/ZTools/ViewModels/Page/SettingViewModel.cs new file mode 100644 index 0000000..ceeb5d1 --- /dev/null +++ b/ZTools/ViewModels/Page/SettingViewModel.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.ObjectModel; +using System.IO; +using System.Text; +using Avalonia; +using Avalonia.Controls; +using Avalonia.Media.Imaging; +using Avalonia.Platform; +using CommunityToolkit.Mvvm.ComponentModel; + +namespace ZTools.ViewModels; + +public partial class Item1: ObservableObject +{ + [ObservableProperty] + private string _name; + [ObservableProperty] + private DateTime _bornDate; + + public override string ToString() + { + return $"Name: {_name}, BornDate: {_bornDate}"; + } +} +public partial class SettingViewModel: PageViewModelBase +{ + private bool _isOpenLog; + private bool _isOnTop; + + public bool IsOpenLog => _isOpenLog; + public bool IsOnTop => _isOnTop; +} \ No newline at end of file diff --git a/ZTools/ViewModels/TestWindowViewModel.cs b/ZTools/ViewModels/TestWindowViewModel.cs new file mode 100644 index 0000000..425c7f9 --- /dev/null +++ b/ZTools/ViewModels/TestWindowViewModel.cs @@ -0,0 +1,8 @@ +using Avalonia.Markup.Xaml.MarkupExtensions; + +namespace ZTools.ViewModels; + +public partial class TestWindowViewModel : ViewModelBase +{ + // public object wc=>Resources.GetResourceObservable("TheKey"); +} \ No newline at end of file diff --git a/ZTools/ViewModels/ViewModelBase.cs b/ZTools/ViewModels/ViewModelBase.cs new file mode 100644 index 0000000..59c5472 --- /dev/null +++ b/ZTools/ViewModels/ViewModelBase.cs @@ -0,0 +1,7 @@ +using CommunityToolkit.Mvvm.ComponentModel; + +namespace ZTools.ViewModels; + +public class ViewModelBase : ObservableObject +{ +} \ No newline at end of file diff --git a/ZTools/Views/FeaturePage.axaml b/ZTools/Views/FeaturePage.axaml new file mode 100644 index 0000000..c42cb4e --- /dev/null +++ b/ZTools/Views/FeaturePage.axaml @@ -0,0 +1,9 @@ + + Welcome to Avalonia! + diff --git a/ZTools/Views/FeaturePage.axaml.cs b/ZTools/Views/FeaturePage.axaml.cs new file mode 100644 index 0000000..6ac649b --- /dev/null +++ b/ZTools/Views/FeaturePage.axaml.cs @@ -0,0 +1,13 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Markup.Xaml; + +namespace ZTools.Views; + +public partial class FeaturePage : Window +{ + public FeaturePage() + { + InitializeComponent(); + } +} \ No newline at end of file diff --git a/ZTools/Views/LogWindow.axaml b/ZTools/Views/LogWindow.axaml new file mode 100644 index 0000000..d382de3 --- /dev/null +++ b/ZTools/Views/LogWindow.axaml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ZTools/Views/LogWindow.axaml.cs b/ZTools/Views/LogWindow.axaml.cs new file mode 100644 index 0000000..b03281f --- /dev/null +++ b/ZTools/Views/LogWindow.axaml.cs @@ -0,0 +1,20 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Interactivity; +using Avalonia.Markup.Xaml; + +namespace ZTools.Views; + +public partial class LogWindow : Window +{ + public LogWindow() + { + InitializeComponent(); + + } + + private void Button_OnClick(object? sender, RoutedEventArgs e) + { + Log.Debug("Click"); + } +} \ No newline at end of file diff --git a/ZTools/Views/MainWindow.axaml b/ZTools/Views/MainWindow.axaml new file mode 100644 index 0000000..8a18578 --- /dev/null +++ b/ZTools/Views/MainWindow.axaml @@ -0,0 +1,127 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ccccc + + + + + + + + + + + + \ No newline at end of file diff --git a/ZTools/Views/MainWindow.axaml.cs b/ZTools/Views/MainWindow.axaml.cs new file mode 100644 index 0000000..01cdd67 --- /dev/null +++ b/ZTools/Views/MainWindow.axaml.cs @@ -0,0 +1,144 @@ +using System.Collections.ObjectModel; +using System.Linq; +using Avalonia; +using Avalonia.Controls; +using Avalonia.Controls.Shapes; +using Avalonia.Interactivity; +using Avalonia.Layout; +using Avalonia.Media; + +namespace ZTools.Views; + +public partial class MainWindow : Window +{ + public MainWindow() + { + InitializeComponent(); + AddColumns(); + // AutoWeight(); + InitAutoDrag(); + } + + private void Button_OpenSetting(object? sender, RoutedEventArgs e) + { + var settingWindow = new SettingWindow(); + settingWindow.Show(); + } + + private void Button_OpenLog(object? sender, RoutedEventArgs e) + { + new LogWindow().Show(); + } + + private void Button_OpenTest(object? sender, RoutedEventArgs e) + { + new TestWindow().Show(); + } + + double _dragStartX; + double _initialWidth; + double _initialRightWidth; + bool _isResizing = false; + + void InitAutoDrag() + { + // MainDockPanel.Children.Add(resizeThumb); + // + // MainDockPanel.Children.Add(resizeThumb1); + + // 监听拖拽区域的PointerPressed事件 + resizeThumb.PointerPressed += (sender, e) => + { + if (e.GetCurrentPoint(MainDockPanel).Properties.IsLeftButtonPressed) + { + _dragStartX = e.GetPosition(this).X; + _initialWidth = MenuDockPanel.Width; + _initialRightWidth = SecondMenuDockPanel.Width; + _isResizing = true; + e.Handled = true; + } + }; + + resizeThumb1.PointerPressed += (sender, e) => + { + if (e.GetCurrentPoint(SecondMenuDockPanel).Properties.IsLeftButtonPressed) + { + _dragStartX = e.GetPosition(this).X; + _initialWidth = SecondMenuDockPanel.Width; + _initialRightWidth = FunctionDockPanel.Width; + _isResizing = true; + e.Handled = true; + } + }; + + // 监听鼠标移动事件,实时更新左侧Panel的宽度 + resizeThumb.PointerMoved += (sender, e) => + { + if (_isResizing) + { + var currentX = e.GetPosition(this).X; + var delta = currentX - _dragStartX; + var updateLeft = _initialWidth + delta; + var updateRight = _initialRightWidth - delta; + MenuDockPanel.Width = updateLeft > 1 ? updateLeft : 1; // 更新左侧Panel的宽度 + SecondMenuDockPanel.Width = updateRight > 1 ? updateRight : 1; + e.Handled = true; + } + }; + resizeThumb1.PointerMoved += (sender, e) => + { + if (_isResizing) + { + var currentX = e.GetPosition(this).X; + var delta = currentX - _dragStartX; + var updateLeft = _initialWidth + delta; + var updateRight = _initialRightWidth - delta; + SecondMenuDockPanel.Width = updateLeft > 1 ? updateLeft : 1; // 更新左侧Panel的宽度 + FunctionDockPanel.Width = _initialRightWidth - delta; // updateRight > 1 ? updateRight : 1; + e.Handled = true; + } + }; + + // 监听鼠标释放事件,结束拖拽 + resizeThumb.PointerReleased += (sender, e) => { _isResizing = false; }; + resizeThumb1.PointerReleased += (sender, e) => { _isResizing = false; }; + } + + private void AddColumns() + { + // Grid myGrid = this.FindControl("myGrid"); + int count = 4; + for (int i = 0; i < 19; i++) // 添加 5 列 + { + var hang = i / count; + var lie = i % count; + Log.Debug($"{hang} : {lie}"); + if (this.myGrid.RowDefinitions.Count < hang + 1) + this.myGrid.RowDefinitions.Add(new RowDefinition(new GridLength(hang, GridUnitType.Auto))); + if (this.myGrid.ColumnDefinitions.Count < lie + 1) + myGrid.ColumnDefinitions.Add(new ColumnDefinition(new GridLength(lie, GridUnitType.Auto))); + + Border border = new Border() + { + Width = 60, + Height = 40, + BorderBrush = Brushes.Black, // 设置边框颜色 + BorderThickness = new Thickness(2), // 设置边框厚度 + Padding = new Thickness(2), // 设置内部填充 + Background = Brushes.LightGray, // 设置背景颜色 + HorizontalAlignment = HorizontalAlignment.Stretch, + VerticalAlignment = VerticalAlignment.Stretch, + }; + var textBlock = new TextBlock + { + Text = $"{hang} : {lie}", + HorizontalAlignment = HorizontalAlignment.Center, + Background = i % 2 == 0 ? Brushes.Red : Brushes.Green, + }; + border.Child = textBlock; + this.myGrid.Children.Add(border); + Grid.SetRow(border, hang); + Grid.SetColumn(border, lie); + } + } +} \ No newline at end of file diff --git a/ZTools/Views/SettingWindow.axaml b/ZTools/Views/SettingWindow.axaml new file mode 100644 index 0000000..b781bb2 --- /dev/null +++ b/ZTools/Views/SettingWindow.axaml @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ZTools/Views/SettingWindow.axaml.cs b/ZTools/Views/SettingWindow.axaml.cs new file mode 100644 index 0000000..55477ef --- /dev/null +++ b/ZTools/Views/SettingWindow.axaml.cs @@ -0,0 +1,25 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Interactivity; +using Avalonia.Markup.Xaml; + +namespace ZTools.Views; + +public partial class SettingWindow : Window +{ + public SettingWindow() + { + InitializeComponent(); + } + + private void ToggleButton_OnIsCheckedThemeChanged(object? sender, RoutedEventArgs e) + { + // e.Handled + Log.Debug(e.Handled); + } + + private void ToggleButton_OnIsCheckedChanged(object? sender, RoutedEventArgs e) + { + + } +} \ No newline at end of file diff --git a/ZTools/Views/TestWindow.axaml b/ZTools/Views/TestWindow.axaml new file mode 100644 index 0000000..8eb29ca --- /dev/null +++ b/ZTools/Views/TestWindow.axaml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ZTools/Views/TestWindow.axaml.cs b/ZTools/Views/TestWindow.axaml.cs new file mode 100644 index 0000000..885700b --- /dev/null +++ b/ZTools/Views/TestWindow.axaml.cs @@ -0,0 +1,33 @@ +using System; +using Avalonia; +using Avalonia.Controls; +using Avalonia.Markup.Xaml; +using Avalonia.Media; +using Avalonia.Media.Imaging; +using Avalonia.Platform; + +namespace ZTools.Views; + +public partial class TestWindow : Window +{ + public TestWindow() + { + InitializeComponent(); + + // found1 = false | result1 = null + var found1 = this.TryGetResource("TheKey", this.ActualThemeVariant, out var result1); + + // found2 = true | result2 = "Hello World" + var found2 = this.TryFindResource("TheKey", this.ActualThemeVariant, out var result2); + + // 从代码中找到资源并将其绑定到 TextBlock + myTextBlock.Bind(TextBlock.TextProperty, Resources.GetResourceObservable("TheKey")); + + var uri = "avares://ZTools/Assets/Menu/其他.png"; + var bitmap = new Bitmap(AssetLoader.Open(new Uri(uri))); + img.Source=bitmap; + + // 通过绑定的 observable 更新 myTextBlock.Text + this.Resources["TheKey"] = "Hello from code behind"; + } +} \ No newline at end of file diff --git a/ZTools/app.manifest b/ZTools/app.manifest new file mode 100644 index 0000000..bffe2c1 --- /dev/null +++ b/ZTools/app.manifest @@ -0,0 +1,18 @@ + + + + + + + + + + + + + +