From b761976f8c87770cef049f8eae09ea9316cdd9d7 Mon Sep 17 00:00:00 2001 From: tanglong <842690096@qq.com> Date: Thu, 25 Sep 2025 09:10:11 +0800 Subject: [PATCH] dd --- Wpf_AiSportsMicrospace/Home.xaml | 2 +- .../MyUserControl/CoverFlowItem.cs | 24 ++++++ .../ProgressToRectangleGeometryConverter.cs | 75 +++++++++++++++++++ 3 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 Wpf_AiSportsMicrospace/MyUserControl/CoverFlowItem.cs create mode 100644 Wpf_AiSportsMicrospace/MyUserControl/ProgressToRectangleGeometryConverter.cs diff --git a/Wpf_AiSportsMicrospace/Home.xaml b/Wpf_AiSportsMicrospace/Home.xaml index 5e8e195..246ea15 100644 --- a/Wpf_AiSportsMicrospace/Home.xaml +++ b/Wpf_AiSportsMicrospace/Home.xaml @@ -2,7 +2,7 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:Wpf_AiSportsMicrospace.MyUserControl" - Title="Home" Height="400" Width="800" Loaded="Window_Loaded"> + Title="Home" Height="600" Width="800" Loaded="Window_Loaded"> diff --git a/Wpf_AiSportsMicrospace/MyUserControl/CoverFlowItem.cs b/Wpf_AiSportsMicrospace/MyUserControl/CoverFlowItem.cs new file mode 100644 index 0000000..2668220 --- /dev/null +++ b/Wpf_AiSportsMicrospace/MyUserControl/CoverFlowItem.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; + +namespace Wpf_AiSportsMicrospace.MyUserControl +{ + public class CoverFlowItem : DependencyObject + { + public Uri ImageUri { get; set; } + + public double Progress + { + get => (double)GetValue(ProgressProperty); + set => SetValue(ProgressProperty, value); + } + + public static readonly DependencyProperty ProgressProperty = + DependencyProperty.Register(nameof(Progress), typeof(double), typeof(CoverFlowItem), new PropertyMetadata(0.0)); + } +} diff --git a/Wpf_AiSportsMicrospace/MyUserControl/ProgressToRectangleGeometryConverter.cs b/Wpf_AiSportsMicrospace/MyUserControl/ProgressToRectangleGeometryConverter.cs new file mode 100644 index 0000000..ebbaf0e --- /dev/null +++ b/Wpf_AiSportsMicrospace/MyUserControl/ProgressToRectangleGeometryConverter.cs @@ -0,0 +1,75 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Data; +using System.Windows.Media; + +namespace Wpf_AiSportsMicrospace.MyUserControl +{ + public class ProgressToRectangleGeometryConverter : IValueConverter + { + // parameter: "width,height" + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + double progress = (double)value; + string[] sizes = parameter.ToString().Split(','); + double width = double.Parse(sizes[0]); + double height = double.Parse(sizes[1]); + + var geo = new StreamGeometry(); + using (var ctx = geo.Open()) + { + ctx.BeginFigure(new Point(0, 0), false, false); + + double total = 2 * (width + height); + double len = progress * total; + + // 上边 + if (len <= width) + { + ctx.LineTo(new Point(len, 0), true, true); + return geo; + } + ctx.LineTo(new Point(width, 0), true, true); + len -= width; + + // 右边 + if (len <= height) + { + ctx.LineTo(new Point(width, len), true, true); + return geo; + } + ctx.LineTo(new Point(width, height), true, true); + len -= height; + + // 下边 + if (len <= width) + { + ctx.LineTo(new Point(width - len, height), true, true); + return geo; + } + ctx.LineTo(new Point(0, height), true, true); + len -= width; + + // 左边 + if (len <= height) + { + ctx.LineTo(new Point(0, height - len), true, true); + } + else + { + ctx.LineTo(new Point(0, 0), true, true); + } + } + geo.Freeze(); + return geo; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + => throw new NotImplementedException(); + } +}