今天开始继续Avalonia练习。
本节:自定义界面
在网上看见一个博客,根据需要演示一下。
前台代码
<Window xmlns="https://github.com/avaloniaui"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:vm="using:WindowStyleAvalonia.ViewModels"xmlns:d="http://schemas.microsoft.com/expression/blend/2008"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"x:Class="WindowStyleAvalonia.Views.MainWindow"x:DataType="vm:MainWindowViewModel"Icon="/Assets/avalonia-logo.ico"Title="WindowStyleAvalonia"><Design.DataContext><!-- This only sets the DataContext for the previewer in an IDE,to set the actual DataContext for runtime, set the DataContext property in code (look at App.axaml.cs) --><vm:MainWindowViewModel/></Design.DataContext><Window.Styles><Style Selector="Window"><Setter Property="ExtendClientAreaToDecorationsHint" Value="True"></Setter><Setter Property="ExtendClientAreaChromeHints" Value="NoChrome"></Setter><Setter Property="ExtendClientAreaTitleBarHeightHint" Value="-1"></Setter><Setter Property="SystemDecorations" Value="None"></Setter><Setter Property="CanResize" Value="False"></Setter><Setter Property="Background"><Setter.Value><SolidColorBrush Color="White" Opacity="0"></SolidColorBrush></Setter.Value></Setter></Style></Window.Styles></Window>
后台代码
using Avalonia.Controls;
using Avalonia.Input;
using System;namespace WindowStyleAvalonia.Views
{public partial class MainWindow : Window{public MainWindow(){InitializeComponent();this.PointerPressed += MainWindow_PointerPressed;}private void MainWindow_PointerPressed(object? sender, PointerPressedEventArgs e){if (e.Pointer.Type == PointerType.Mouse){this.BeginMoveDrag(e);}}}
}
运行效果
另外推荐一个博文:
Avalonia 实现跨平台的视频聊天、屏幕分享(源码,支持Win、银河麒麟、统信UOS)-CSDN博客