1.项目下载地址:https://gitee.com/confusedkitten/avalonia-demo
2.UI库Semi.Avalonia,项目地址 https://github.com/irihitech/Semi.Avalonia\
样式预览:
axaml代码 :
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="using:AvaloniaDemo.ViewModels"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="AvaloniaDemo.Pages.Slider"
x:DataType="vm:SliderViewModel">
<Grid VerticalAlignment="Center" Background="Transparent">
<StackPanel>
<Slider TickFrequency="1" Background="LightGray" Height="40" Minimum="0" Maximum="100" Value="0" Margin="0 3 0 0"
x:Name="SliderProgress" ValueChanged="SliderValueChanged"
PointerPressed="SliderPreviewMouseDown"
PointerReleased="SliderPreviewMouseUp"
PointerMoved="SliderProgress_MouseMove"
PointerCaptureLost="SliderProgress_LostMouseCapture"
ToolTip.Placement="Bottom"
ToolTip.VerticalOffset="{Binding VerticalOffset}"
ToolTip.HorizontalOffset="{Binding HorizontalOffset}">
<ToolTip.Tip>
<ToolTip>
<TextBlock Text="{Binding ToolTip}" Foreground="Black"></TextBlock>
</ToolTip>
</ToolTip.Tip>
</Slider>
</StackPanel>
</Grid>
</UserControl>
后台代码:
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.Input;
using Avalonia.Markup.Xaml;
using AvaloniaDemo.ViewModels;
using System.Threading;
namespace AvaloniaDemo.Pages;
public partial class Slider : UserControl
{
public SliderViewModel repeatModel = new SliderViewModel();
public Slider()
{
InitializeComponent();
this.DataContext = repeatModel;
}
/// <summary>
/// 进度条的值发生改变触发事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void SliderValueChanged(object sender, RangeBaseValueChangedEventArgs e)
{
}
/// <summary>
/// 鼠标开始拖拽进度条
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void SliderPreviewMouseDown(object sender, PointerPressedEventArgs e)
{
}
/// <summary>
/// 鼠标结束拖拽进度条
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void SliderPreviewMouseUp(object sender, PointerReleasedEventArgs e)
{
}
/// <summary>
/// 提示
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void SliderProgress_MouseMove(object sender, PointerEventArgs e)
{
repeatModel.ToolTip = SliderProgress.Value.ToString("F2");
var position = e.GetPosition(SliderProgress);
repeatModel.VerticalOffset = position.Y - 80;
repeatModel.HorizontalOffset = position.X - 600;
}
private void SliderProgress_LostMouseCapture(object sender, PointerCaptureLostEventArgs e)
{
}
}