Avalonia学习(二十一)-自定义界面演示
2024-01-09 06:16:18
今天开始继续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);
}
}
}
}
运行效果
另外推荐一个博文:
文章来源:https://blog.csdn.net/jinyuttt/article/details/135468739
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!