Avalonia常用小控件Slider

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)
    {
    }
}
相关推荐
time3 天前
适用于.net的操作excel的库
c#·.net·excel·avalonia
智汇IOT2 个月前
Avalonia跨平台上位机控件开发之水泵
c#·上位机·avalonia
zzlyx992 个月前
Avalonia环境如何安装及安装问题解决
avalonia
假装我不帅5 个月前
vscode开发avalonia
ide·vscode·编辑器·avalonia
lishuangquan19875 个月前
AvaloniaUI的学习
ui·avalonia
Setli5 个月前
.NET跨平台UI框架Avalonia 11.1重磅发布
.net·跨平台·avalonia
hoyho7 个月前
分享下最近基于Avalonia UI和MAUI写跨平台时间管理工具的体验
.net·maui·avalonia
czwy7 个月前
Avalonia中的线性渐变画刷LinearGradientBrush
wpf·xaml·avalonia
jason成都10 个月前
Avalonia学习(二十六)-桌面系统界面Ribbon
学习·ui·avalonia
jason成都10 个月前
Avalonia学习(二十五)-系统界面
学习·ui·avalonia