佛山网红书店成都有实力的seo团队
佛山网红书店,成都有实力的seo团队,seo好学吗,上市公司网站建设方案Avalonia制作仪表盘#xff0c;把控件给大家演示一下#xff0c;Avalonia有三类自定义控件#xff0c;分别是用户控件、模版控件、自主控件。前面已经很多用户控件了#xff0c;这个是演示模版控件#xff0c;另外一种不知道哪种情况下使用。
前端代码#xff1a;
…Avalonia制作仪表盘把控件给大家演示一下Avalonia有三类自定义控件分别是用户控件、模版控件、自主控件。前面已经很多用户控件了这个是演示模版控件另外一种不知道哪种情况下使用。
前端代码
Styles xmlnshttps://github.com/avaloniauixmlns:xhttp://schemas.microsoft.com/winfx/2006/xamlxmlns:localclr-namespace:GaugeAvalonia.Views;assemblyGaugeAvaloniax:CompileBindingsFalseDesign.PreviewWithBorder Padding20!-- Add Controls for Previewer Here --/Border/Design.PreviewWithStyle Selectorlocal|ArcGaugeSetter PropertyBackground Value#646464/Setter PropertyForeground ValueBlack/Setter PropertyTemplateSetter.ValueControlTemplate TargetType{x:Type local:ArcGauge}Border Margin10Grid Width{Binding RelativeSource{RelativeSource Self},PathHeight}Ellipse Fill#FF3B3B3B/Grid RenderTransformOrigin0.5,0.5 Margin2Grid.RenderTransformTransformGroupRotateTransform Angle{Binding Angle}//TransformGroup/Grid.RenderTransformEllipse Width16 Height14 FillOrange VerticalAlignmentTop Ellipse.EffectBlurEffect Radius12//Ellipse.Effect/Ellipse/GridGrid x:NamebdGrid Margin12 UseLayoutRoundingTrue ClipToBoundsTrueEllipseEllipse.FillRadialGradientBrushGradientStop Color#4D000000//RadialGradientBrush/Ellipse.Fill/EllipseGridGrid.ColumnDefinitionsColumnDefinition/ColumnDefinition Width2*/ColumnDefinition//Grid.ColumnDefinitionsGrid.RowDefinitionsRowDefinition/RowDefinition Height2*/RowDefinition//Grid.RowDefinitionsEllipse Stroke#464646 StrokeThickness1 Grid.Column1 Grid.Row1/Ellipse Stroke#959595 Margin4 StrokeThickness6 Grid.Column1 Grid.Row1/Ellipse Stroke#464646 Margin14 StrokeThickness1 Grid.Column1 Grid.Row1//GridGridGrid.RowDefinitionsRowDefinition/RowDefinition//Grid.RowDefinitionsPath DataM5,0 5,0 10,120 0,120z Fill#0FA9CE StretchUniform Margin0 30 0 0 HorizontalAlignmentCenterPath.RenderTransformTransformGroupRotateTransform Angle{Binding PathAngle, ModeTwoWay}//TransformGroup/Path.RenderTransform/Path/GridEllipse Width28 Height28 FillBlackEllipse.Effect!--DropShadowEffect Color#0FA9CE ShadowDepth0 Direction0 BlurRadius16/--/Ellipse.Effect/EllipseBorder VerticalAlignmentBottom BorderBrush#10ABD1 BorderThickness2 Margin0 0 0 12 BackgroundBlack Padding8 2 HorizontalAlignmentCenterTextBlock Text{Binding Value,RelativeSource{RelativeSource ModeTemplatedParent}} FontSize16 Width30 TextAlignmentCenter ForegroundWhite FontWeightBold//Border/Grid/Grid/Border/ControlTemplate/Setter.Value/Setter/Style/Styles后台代码
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Shapes;
using Avalonia.Media;
using System.Collections.Generic;
using System.ComponentModel;
using Avalonia.Controls.Templates;
using Avalonia.Controls.Primitives;
using System.Linq;namespace GaugeAvalonia.Views
{public class ArcGauge: TemplatedControl{Grid bdGrid;static ArcGauge(){// DefaultStyleKeyProperty.OverrideMetadata(typeof(ArcGauge), new FrameworkPropertyMetadata(typeof(ArcGauge)));}public ArcGauge(){this.Loaded ArcGauge_Loaded;//Width 200;//Height 200;SetCurrentValue(ValueProperty, 0d);SetCurrentValue(MinValueProperty, 0d);SetCurrentValue(MaxValueProperty, 100d);}private void ArcGauge_Loaded(object? sender, Avalonia.Interactivity.RoutedEventArgs e){InitTick();}public override void Render(DrawingContext context){base.Render(context);bdGrid (Grid)this.GetTemplateChildren().Where(x x.Name bdGrid).First();Refresh();}private void InitTick(){// 画大刻度for (int i 0; i 9; i){Line line new Line();line.StartPoint new Point(0, 0);line.EndPointnew Point(0, 12);line.HorizontalAlignment Avalonia.Layout.HorizontalAlignment.Center;line.Stroke Brushes.White;line.StrokeThickness 2;line.RenderTransformOrigin RelativePoint.Center;line.RenderTransform new RotateTransform() { Angle -140 i * 35 };bdGrid.Children.Add(line);DrawText();} // 画小刻度for (int i 0; i 8; i){var start -140 35 * i 3.5;for (int j 0; j 9; j){Line line new Line();line.StartPoint new Point(0, 0);line.EndPoint new Point(0, 6);line.Stroke Brushes.White;line.StrokeThickness 1;line.HorizontalAlignment Avalonia.Layout.HorizontalAlignment .Center;line.RenderTransformOrigin RelativePoint.Center;line.RenderTransform new RotateTransform() { Angle start j * 3.5 };bdGrid.Children.Add(line);}}}ListTextBlock textLabels new ListTextBlock();private void DrawText(){foreach (var item in textLabels){bdGrid.Children.Remove(item);}textLabels.Clear();var per MaxValue / 8;for (int i 0; i 9; i){TextBlock textBlock new TextBlock();textBlock.Text ${MinValue (per * i)};textBlock.HorizontalAlignment Avalonia.Layout.HorizontalAlignment.Center;textBlock.RenderTransformOrigin RelativePoint.Center;textBlock.RenderTransform new RotateTransform() { Angle -140 i * 35 };textBlock.Margin new Thickness(12);textBlock.Foreground Brushes.White;bdGrid.Children.Add(textBlock);textLabels.Add(textBlock);}}//public static readonly StyledPropertyIBrush BackgroundProperty // AvaloniaProperty.RegisterArcGauge, IBrush(nameof(Value));//public IBrush Background//{// get// {// return GetValue(BackgroundProperty);// }// set// {// SetValue(BackgroundProperty, value);// }//}//public static readonly StyledPropertyIBrush ForegroundProperty // AvaloniaProperty.RegisterArcGauge, IBrush(nameof(Value));//public IBrush Foreground//{// get// {// return GetValue(ForegroundProperty);// }// set// {// SetValue(ForegroundProperty, value);// }// }[Category(值设定)]public double Value{get { return (double)GetValue(ValueProperty); }set { SetValue(ValueProperty, value); }}public static readonly StyledPropertydouble ValueProperty AvaloniaProperty.RegisterArcGauge, double(nameof(Value), coerce: OnValueChanged);private static double OnValueChanged(AvaloniaObject object, double arg2){ArcGauge gauge object as ArcGauge;gauge.Refresh();return arg2;}[Category(值设定)]public double MinValue{get { return (double)GetValue(MinValueProperty); }set { SetValue(MinValueProperty, value); }}public static readonly StyledPropertydouble MinValueProperty AvaloniaProperty.RegisterArcGauge, double(nameof(MinValue), coerce: OnValueChanged);public double MaxValue{get { return (double)GetValue(MaxValueProperty); }set { SetValue(MaxValueProperty, value); }}public static readonly StyledPropertydouble MaxValueProperty AvaloniaProperty.RegisterArcGauge, double(nameof(MaxValue), coerce: OnValueChanged);public double Angle{get { return (double)GetValue(AngleProperty); }set { SetValue(AngleProperty, value); }}public static readonly StyledPropertydouble AngleProperty AvaloniaProperty.RegisterArcGauge, double(nameof(Angle));private void Refresh(){if (Value MaxValue){Angle 140;}else if (Value MinValue){Angle -140;}else{var range MaxValue - MinValue;var process Value / range;var tAngle process * 280 - 140;Angle tAngle;}}}
}
运行效果 目前Avalonia的内容也不知道该演示什么了。估计博文会更新慢了。
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/diannao/89373.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!