Loading CountDownList/Class/ListCore.cs +116 −67 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ namespace CountDownList.Class { public StackPanel DoingPanel , WcPanel, CountPanel; public Expander DoingE, WcE, CountE; public FrameworkElement RootWindow; public bool IsOpen = true; public ListCore Loading @@ -28,16 +29,20 @@ namespace CountDownList.Class StackPanel wcPanel, StackPanel countPanel, Expander doingE, Expander WcE, Expander countE Expander wcE, Expander countE, FrameworkElement Window ) { DoingPanel = doingPanel; WcPanel = wcPanel; CountPanel = countPanel; DoingE = doingE; WcE = WcE; WcE = wcE; CountE = countE; RootWindow = Window; RefreshNumber(); } private async void RefreshNumber() Loading @@ -63,12 +68,13 @@ namespace CountDownList.Class /// <param name="brush">背景画刷</param> /// <param name="InsertIndex">插入的位置,为null则插到最后</param> public async void AddCountDownLabel(string t, DateTime st, DateTime et, string f, bool dark, Brush brush, int? InsertIndex = null) { //自动释放资源 using (ListLabel lb = new(t, st, et, f, dark, brush, false)) { bool Move = false; //动态添加控件 Controls.ListLabel lb; lb = new(t, st, et, f, dark, brush, false); lb.Uid = t; //事件绑定 Loading @@ -85,7 +91,7 @@ namespace CountDownList.Class DoingPanel.Children.Add(lb); } while (true) while (!lb.IsDelete) { if (DateTime.Now <= et) { Loading @@ -93,12 +99,15 @@ namespace CountDownList.Class //当展开框展开时才刷新控件,以优化性能 if (DoingE.IsExpanded && IsOpen) { if (IsUserVisible(lb, RootWindow)) { lb.SyncProgress(); lb.SyncTime(); lb.SyncTitle(); } } } else { //当不是正计时并且已完成 Loading @@ -109,9 +118,16 @@ namespace CountDownList.Class DoingPanel.Children.Remove(lb);//从进行中移除控件 WcPanel.Children.Add(lb);//添加到已完成 if (!IsUserVisible(lb, RootWindow)) { await Task.Delay(250); } } if (WcE.IsExpanded && IsOpen) if (WcE.IsExpanded && IsOpen && IsUserVisible(lb, RootWindow)) { if (IsUserVisible(lb, RootWindow)) { //当展开框展开时才刷新控件,以优化性能 lb.SyncProgress(); Loading @@ -119,7 +135,17 @@ namespace CountDownList.Class lb.SyncTitle(); } } await Task.Delay(20); } if (lb.IsMouseEnter || lb.Open) { await Task.Delay(15); } else { await Task.Delay(75); } } } } Loading Loading @@ -153,10 +179,10 @@ namespace CountDownList.Class /// <param name="dark">深色文本</param> /// <param name="brush">背景画刷</param> public async void AddCountLabel(string t, DateTime st, string f, bool dark, Brush brush, int? InsertIndex = null) { using (ListLabel lb = new(t, st, new(), f, dark, brush, true)) { //动态添加控件 ListLabel lb; lb = new(t, st, new(), f, dark, brush, true); lb.Uid = t; if (InsertIndex != null) Loading @@ -174,12 +200,24 @@ namespace CountDownList.Class //当不是正计时时执行 //当展开框展开时才刷新控件,以优化性能 if (CountE.IsExpanded && IsOpen) { if (IsUserVisible(lb, RootWindow)) { lb.SyncProgress(); lb.SyncTime(); lb.SyncTitle(); } await Task.Delay(20); } if (lb.IsMouseEnter || lb.Open) { await Task.Delay(15); } else { await Task.Delay(75); } } } } Loading Loading @@ -400,6 +438,7 @@ namespace CountDownList.Class window.ShowDialog(); if (window.EditResult != null) { labelElement.IsDelete = true; DeleteForElement(labelElement); if (window.EditResult.IsCountMode) { Loading @@ -411,5 +450,15 @@ namespace CountDownList.Class } } } private bool IsUserVisible(FrameworkElement element, FrameworkElement container) { if (!element.IsVisible) return false; Rect bounds = element.TransformToAncestor(container).TransformBounds(new Rect(0.0, 0.0, element.ActualWidth, element.ActualHeight)); Rect rect = new Rect(0.0, 0.0, container.ActualWidth, container.ActualHeight); return rect.Contains(bounds.TopLeft) || rect.Contains(bounds.BottomRight); } } } CountDownList/Controls/ListLabel.xaml +4 −1 Original line number Diff line number Diff line Loading @@ -4,7 +4,10 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:CountDownList.Controls" mc:Ignorable="d" Height="85" Width="384"> RenderOptions.BitmapScalingMode="HighQuality" TextOptions.TextHintingMode="Auto" RenderOptions.ClearTypeHint="Enabled" mc:Ignorable="d" Height="85" Width="384" MouseEnter="userControl_MouseEnter" MouseLeave="userControl_MouseLeave"> <UserControl.Resources> <Storyboard x:Key="Storyboard1"> <DoubleAnimationUsingKeyFrames Storyboard.TargetName="userControl" Storyboard.TargetProperty="(FrameworkElement.Height)"> Loading CountDownList/Controls/ListLabel.xaml.cs +104 −48 Original line number Diff line number Diff line Loading @@ -14,13 +14,15 @@ using System.Windows.Media.Animation; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using static System.Windows.Forms.DataFormats; using static System.Windows.Forms.VisualStyles.VisualStyleElement.TrayNotify; namespace CountDownList.Controls { /// <summary> /// ListLabel.xaml 的交互逻辑 /// </summary> public partial class ListLabel : UserControl public partial class ListLabel : UserControl , IDisposable { //属性 public string Title { get; set; } Loading @@ -37,6 +39,7 @@ namespace CountDownList.Controls public event EventHandler<EventArgs>? OnShare; public string? TimeFormat; public bool IsDelete = false; public bool InPreview { get; set; } = false; Loading Loading @@ -65,6 +68,22 @@ namespace CountDownList.Controls SyncProgress(); SyncTextColor(); SyncBackground(); } private bool IsStop; public void Dispose() { IsStop = true; // 解除所有绑定 BindingOperations.ClearAllBindings(this); // 解除事件处理程序 this.Unloaded -= Button_Click; GC.Collect(); GC.SuppressFinalize(this); } private void Button_Click(object sender, RoutedEventArgs e) Loading @@ -72,9 +91,17 @@ namespace CountDownList.Controls ((ContextMenu)FindResource("ContextMenu")).IsOpen = true; } bool Open = false; private void Border_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { public bool Open = false; private async void Border_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { TextOptions.SetTextHintingMode(this, TextHintingMode.Animated); TextOptions.SetTextHintingMode(TitleText, TextHintingMode.Animated); TextOptions.SetTextHintingMode(TitleTextFull, TextHintingMode.Animated); TextOptions.SetTextHintingMode(TimeText, TextHintingMode.Animated); TextOptions.SetTextHintingMode(TimeTextFull, TextHintingMode.Animated); TextOptions.SetTextHintingMode(ProgressText, TextHintingMode.Animated); TextOptions.SetTextHintingMode(ProgressTextFull, TextHintingMode.Animated); if (Open) { Open = false; Loading @@ -85,6 +112,13 @@ namespace CountDownList.Controls Open = true; ((Storyboard)FindResource("Storyboard1")).Begin(); } await Task.Delay(750); TextOptions.SetTextHintingMode(TitleText, TextHintingMode.Auto); TextOptions.SetTextHintingMode(TitleTextFull, TextHintingMode.Auto); TextOptions.SetTextHintingMode(TimeText, TextHintingMode.Auto); TextOptions.SetTextHintingMode(TimeTextFull, TextHintingMode.Auto); TextOptions.SetTextHintingMode(ProgressText, TextHintingMode.Auto); TextOptions.SetTextHintingMode(ProgressTextFull, TextHintingMode.Auto); } public void SyncTitle() Loading @@ -109,6 +143,8 @@ namespace CountDownList.Controls } public void SyncTime() { if (!IsStop) { if (IsCountMode) { Loading @@ -123,8 +159,11 @@ namespace CountDownList.Controls TimeTextFull.Text = (EndTime - DateTime.Now).ToString(TimeFormat); } } } public void SyncProgress() { if (!IsStop) { if (IsCountMode) { Loading @@ -135,6 +174,7 @@ namespace CountDownList.Controls } else { ProgressBar.Visibility = Visibility.Visible; if (!((EndTime - DateTime.Now).TotalMilliseconds <= 0d)) { Progress = ((EndTime - DateTime.Now).TotalMilliseconds / (EndTime - StartTime).TotalMilliseconds) * 100; Loading @@ -152,11 +192,14 @@ namespace CountDownList.Controls } } } } SolidColorBrush Dark = new(Color.FromArgb(255, 32, 32, 32)); SolidColorBrush Light = new(Color.FromArgb(255, 247, 247, 247)); public void SyncTextColor() { if (!IsStop) { if (DarkText) { Loading @@ -179,9 +222,11 @@ namespace CountDownList.Controls TimeTextFull.Foreground = Light; } } } public void SyncBackground() { if(!IsStop) bg.Background = LabelBackground; } Loading Loading @@ -221,6 +266,17 @@ namespace CountDownList.Controls MessageBox.Show("在预览模式下无法执行分享操作", Title, MessageBoxButton.OK, MessageBoxImage.Warning, MessageBoxResult.OK, MessageBoxOptions.ServiceNotification); } } public bool IsMouseEnter = false; private void userControl_MouseEnter(object sender, MouseEventArgs e) { IsMouseEnter = true; } private void userControl_MouseLeave(object sender, MouseEventArgs e) { IsMouseEnter = false; } #pragma warning restore CS8602 // 解引用可能出现空引用。 } } CountDownList/MainWindow.xaml +13 −4 Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:CountDownList" mc:Ignorable="d" RenderOptions.ClearTypeHint="Enabled" xmlns:control="clr-namespace:CountDownList.Controls" xmlns:hc="https://handyorg.github.io/handycontrol" xmlns:local1="clr-namespace:CountDownList.Class" Title="MainWindow" Height="500" Width="392" Background="{x:Null}" ResizeMode="CanMinimize" WindowStyle="None"> Loading Loading @@ -131,19 +132,27 @@ </TransformGroup> </Border.RenderTransform> <Grid Margin="0,4,0,4"> <local:MyScrollViewer VirtualizingStackPanel.IsVirtualizing="True" VirtualizingStackPanel.VirtualizationMode="Standard" VerticalScrollBarVisibility="Hidden"> <local:MyScrollViewer x:Name="sv" VirtualizingStackPanel.IsVirtualizing="True" VirtualizingStackPanel.VirtualizationMode="Standard" VerticalScrollBarVisibility="Hidden"> <local:MyScrollViewer.OpacityMask> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="Transparent"/> <GradientStop Color="Transparent" Offset="1"/> <GradientStop Color="White" Offset="0.02"/> <GradientStop Color="White" Offset="0.98"/> </LinearGradientBrush> </local:MyScrollViewer.OpacityMask> <StackPanel> <Expander x:Name="DoingE" Background="#00F7F7F7" BorderBrush="{x:Null}" IsExpanded="True" Header="进行中(5)" Margin="4,0,4,0" Foreground="#FFF7F7F7"> <Expander RenderOptions.ClearTypeHint="Enabled" x:Name="DoingE" Background="#00F7F7F7" BorderBrush="{x:Null}" IsExpanded="True" Header="进行中(5)" Margin="4,0,4,0" Foreground="#FFF7F7F7"> <StackPanel x:Name="doingList"> </StackPanel> </Expander> <Expander x:Name="countE" Background="#00000000" BorderBrush="{x:Null}" Header="正计时(5)" Margin="4,0,4,0" Foreground="#FFF7F7F7" IsExpanded="True"> <Expander RenderOptions.ClearTypeHint="Enabled" x:Name="countE" Background="#00000000" BorderBrush="{x:Null}" Header="正计时(5)" Margin="4,0,4,0" Foreground="#FFF7F7F7" IsExpanded="True"> <StackPanel x:Name="count"> </StackPanel> </Expander> <Expander x:Name="wcE" Background="#00000000" BorderBrush="{x:Null}" Header="已完成(5)" Margin="4,0,4,0" Foreground="#FFF7F7F7"> <Expander RenderOptions.ClearTypeHint="Enabled" x:Name="wcE" Background="#00000000" BorderBrush="{x:Null}" Header="已完成(5)" Margin="4,0,4,0" Foreground="#FFF7F7F7"> <StackPanel x:Name="wancheng"> </StackPanel> Loading CountDownList/MainWindow.xaml.cs +9 −7 Original line number Diff line number Diff line Loading @@ -39,18 +39,20 @@ namespace CountDownList zkImageTest.ImageSource = new BitmapImage(new Uri(@"Data\Image\4.jpg", UriKind.Relative)); zkImageTest.Stretch = Stretch.UniformToFill; AddTest("跨年倒计时!",new(2024,1,1),new(2025,1,1), "dd\\天hh\\:mm\\:ss",false, NewYearImageTest); AddTest("2025春节", new(2024, 2, 10), new(2025, 1, 29), "dd\\天hh\\:mm\\:ss", false, NewYearImageTest); AddCount("去年生日", new(2024, 8, 7), "dd\\天hh\\:mm\\:ss", true, BirthImageTest); AddCount("中考", new(2024, 6, 24), "dd\\天hh\\:mm\\:ss", true, zkImageTest); AddTest("明年生日", new(2024, 8, 7), new(2025,8,7), "dd\\天hh\\:mm\\:ss", true, BirthImageTest); DoingE.Header = $"进行中({doingList.Children.Count})"; wcE.Header = $"已完成({wancheng.Children.Count})"; countE.Header = $"正计时({count.Children.Count})"; Core = new(doingList, wancheng, count, DoingE, wcE, countE); Core = new(doingList, wancheng, count, DoingE, wcE, countE,sv); Core.AddCountDownLabel("跨年倒计时!(ListCore生成的)", new(2024, 1, 1), new(2025, 1, 1), "dd\\天hh\\:mm\\:ss", false, NewYearImageTest); Core.AddCountDownLabel("跨年倒计时!", new(2024, 1, 1), new(2025, 1, 1), "dd\\天hh\\:mm\\:ss", false, NewYearImageTest); Core.AddCountDownLabel("2025春节", new(2024, 2, 10), new(2025, 1, 29), "dd\\天hh\\:mm\\:ss", false, NewYearImageTest); Core.AddCountLabel("去年生日", new(2024, 8, 7), "dd\\天hh\\:mm\\:ss", true, BirthImageTest); Core.AddCountLabel("中考", new(2024, 6, 24), "dd\\天hh\\:mm\\:ss", true, zkImageTest); Core.AddCountDownLabel("明年生日", new(2024, 8, 7), new(2025, 8, 7), "dd\\天hh\\:mm\\:ss", true, BirthImageTest); } ImageBrush NewYearImageTest = new(); Loading Loading @@ -211,7 +213,7 @@ namespace CountDownList (byte)new Random(DateTime.Now.Nanosecond).Next(32, 233) ) ); AddTest("一分钟后", DateTime.Now, DateTime.Now.AddMinutes(1), "dd\\天hh\\:mm\\:ss",Convert.ToBoolean(new Random(DateTime.Now.Nanosecond).Next(0, 1)),brush); Core.AddCountDownLabel("一分钟后", DateTime.Now, DateTime.Now.AddMinutes(1), "dd\\天hh\\:mm\\:ss",Convert.ToBoolean(new Random(DateTime.Now.Nanosecond).Next(0, 1)),brush); DoingE.Header = $"进行中({doingList.Children.Count})"; } Loading Loading
CountDownList/Class/ListCore.cs +116 −67 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ namespace CountDownList.Class { public StackPanel DoingPanel , WcPanel, CountPanel; public Expander DoingE, WcE, CountE; public FrameworkElement RootWindow; public bool IsOpen = true; public ListCore Loading @@ -28,16 +29,20 @@ namespace CountDownList.Class StackPanel wcPanel, StackPanel countPanel, Expander doingE, Expander WcE, Expander countE Expander wcE, Expander countE, FrameworkElement Window ) { DoingPanel = doingPanel; WcPanel = wcPanel; CountPanel = countPanel; DoingE = doingE; WcE = WcE; WcE = wcE; CountE = countE; RootWindow = Window; RefreshNumber(); } private async void RefreshNumber() Loading @@ -63,12 +68,13 @@ namespace CountDownList.Class /// <param name="brush">背景画刷</param> /// <param name="InsertIndex">插入的位置,为null则插到最后</param> public async void AddCountDownLabel(string t, DateTime st, DateTime et, string f, bool dark, Brush brush, int? InsertIndex = null) { //自动释放资源 using (ListLabel lb = new(t, st, et, f, dark, brush, false)) { bool Move = false; //动态添加控件 Controls.ListLabel lb; lb = new(t, st, et, f, dark, brush, false); lb.Uid = t; //事件绑定 Loading @@ -85,7 +91,7 @@ namespace CountDownList.Class DoingPanel.Children.Add(lb); } while (true) while (!lb.IsDelete) { if (DateTime.Now <= et) { Loading @@ -93,12 +99,15 @@ namespace CountDownList.Class //当展开框展开时才刷新控件,以优化性能 if (DoingE.IsExpanded && IsOpen) { if (IsUserVisible(lb, RootWindow)) { lb.SyncProgress(); lb.SyncTime(); lb.SyncTitle(); } } } else { //当不是正计时并且已完成 Loading @@ -109,9 +118,16 @@ namespace CountDownList.Class DoingPanel.Children.Remove(lb);//从进行中移除控件 WcPanel.Children.Add(lb);//添加到已完成 if (!IsUserVisible(lb, RootWindow)) { await Task.Delay(250); } } if (WcE.IsExpanded && IsOpen) if (WcE.IsExpanded && IsOpen && IsUserVisible(lb, RootWindow)) { if (IsUserVisible(lb, RootWindow)) { //当展开框展开时才刷新控件,以优化性能 lb.SyncProgress(); Loading @@ -119,7 +135,17 @@ namespace CountDownList.Class lb.SyncTitle(); } } await Task.Delay(20); } if (lb.IsMouseEnter || lb.Open) { await Task.Delay(15); } else { await Task.Delay(75); } } } } Loading Loading @@ -153,10 +179,10 @@ namespace CountDownList.Class /// <param name="dark">深色文本</param> /// <param name="brush">背景画刷</param> public async void AddCountLabel(string t, DateTime st, string f, bool dark, Brush brush, int? InsertIndex = null) { using (ListLabel lb = new(t, st, new(), f, dark, brush, true)) { //动态添加控件 ListLabel lb; lb = new(t, st, new(), f, dark, brush, true); lb.Uid = t; if (InsertIndex != null) Loading @@ -174,12 +200,24 @@ namespace CountDownList.Class //当不是正计时时执行 //当展开框展开时才刷新控件,以优化性能 if (CountE.IsExpanded && IsOpen) { if (IsUserVisible(lb, RootWindow)) { lb.SyncProgress(); lb.SyncTime(); lb.SyncTitle(); } await Task.Delay(20); } if (lb.IsMouseEnter || lb.Open) { await Task.Delay(15); } else { await Task.Delay(75); } } } } Loading Loading @@ -400,6 +438,7 @@ namespace CountDownList.Class window.ShowDialog(); if (window.EditResult != null) { labelElement.IsDelete = true; DeleteForElement(labelElement); if (window.EditResult.IsCountMode) { Loading @@ -411,5 +450,15 @@ namespace CountDownList.Class } } } private bool IsUserVisible(FrameworkElement element, FrameworkElement container) { if (!element.IsVisible) return false; Rect bounds = element.TransformToAncestor(container).TransformBounds(new Rect(0.0, 0.0, element.ActualWidth, element.ActualHeight)); Rect rect = new Rect(0.0, 0.0, container.ActualWidth, container.ActualHeight); return rect.Contains(bounds.TopLeft) || rect.Contains(bounds.BottomRight); } } }
CountDownList/Controls/ListLabel.xaml +4 −1 Original line number Diff line number Diff line Loading @@ -4,7 +4,10 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:CountDownList.Controls" mc:Ignorable="d" Height="85" Width="384"> RenderOptions.BitmapScalingMode="HighQuality" TextOptions.TextHintingMode="Auto" RenderOptions.ClearTypeHint="Enabled" mc:Ignorable="d" Height="85" Width="384" MouseEnter="userControl_MouseEnter" MouseLeave="userControl_MouseLeave"> <UserControl.Resources> <Storyboard x:Key="Storyboard1"> <DoubleAnimationUsingKeyFrames Storyboard.TargetName="userControl" Storyboard.TargetProperty="(FrameworkElement.Height)"> Loading
CountDownList/Controls/ListLabel.xaml.cs +104 −48 Original line number Diff line number Diff line Loading @@ -14,13 +14,15 @@ using System.Windows.Media.Animation; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using static System.Windows.Forms.DataFormats; using static System.Windows.Forms.VisualStyles.VisualStyleElement.TrayNotify; namespace CountDownList.Controls { /// <summary> /// ListLabel.xaml 的交互逻辑 /// </summary> public partial class ListLabel : UserControl public partial class ListLabel : UserControl , IDisposable { //属性 public string Title { get; set; } Loading @@ -37,6 +39,7 @@ namespace CountDownList.Controls public event EventHandler<EventArgs>? OnShare; public string? TimeFormat; public bool IsDelete = false; public bool InPreview { get; set; } = false; Loading Loading @@ -65,6 +68,22 @@ namespace CountDownList.Controls SyncProgress(); SyncTextColor(); SyncBackground(); } private bool IsStop; public void Dispose() { IsStop = true; // 解除所有绑定 BindingOperations.ClearAllBindings(this); // 解除事件处理程序 this.Unloaded -= Button_Click; GC.Collect(); GC.SuppressFinalize(this); } private void Button_Click(object sender, RoutedEventArgs e) Loading @@ -72,9 +91,17 @@ namespace CountDownList.Controls ((ContextMenu)FindResource("ContextMenu")).IsOpen = true; } bool Open = false; private void Border_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { public bool Open = false; private async void Border_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { TextOptions.SetTextHintingMode(this, TextHintingMode.Animated); TextOptions.SetTextHintingMode(TitleText, TextHintingMode.Animated); TextOptions.SetTextHintingMode(TitleTextFull, TextHintingMode.Animated); TextOptions.SetTextHintingMode(TimeText, TextHintingMode.Animated); TextOptions.SetTextHintingMode(TimeTextFull, TextHintingMode.Animated); TextOptions.SetTextHintingMode(ProgressText, TextHintingMode.Animated); TextOptions.SetTextHintingMode(ProgressTextFull, TextHintingMode.Animated); if (Open) { Open = false; Loading @@ -85,6 +112,13 @@ namespace CountDownList.Controls Open = true; ((Storyboard)FindResource("Storyboard1")).Begin(); } await Task.Delay(750); TextOptions.SetTextHintingMode(TitleText, TextHintingMode.Auto); TextOptions.SetTextHintingMode(TitleTextFull, TextHintingMode.Auto); TextOptions.SetTextHintingMode(TimeText, TextHintingMode.Auto); TextOptions.SetTextHintingMode(TimeTextFull, TextHintingMode.Auto); TextOptions.SetTextHintingMode(ProgressText, TextHintingMode.Auto); TextOptions.SetTextHintingMode(ProgressTextFull, TextHintingMode.Auto); } public void SyncTitle() Loading @@ -109,6 +143,8 @@ namespace CountDownList.Controls } public void SyncTime() { if (!IsStop) { if (IsCountMode) { Loading @@ -123,8 +159,11 @@ namespace CountDownList.Controls TimeTextFull.Text = (EndTime - DateTime.Now).ToString(TimeFormat); } } } public void SyncProgress() { if (!IsStop) { if (IsCountMode) { Loading @@ -135,6 +174,7 @@ namespace CountDownList.Controls } else { ProgressBar.Visibility = Visibility.Visible; if (!((EndTime - DateTime.Now).TotalMilliseconds <= 0d)) { Progress = ((EndTime - DateTime.Now).TotalMilliseconds / (EndTime - StartTime).TotalMilliseconds) * 100; Loading @@ -152,11 +192,14 @@ namespace CountDownList.Controls } } } } SolidColorBrush Dark = new(Color.FromArgb(255, 32, 32, 32)); SolidColorBrush Light = new(Color.FromArgb(255, 247, 247, 247)); public void SyncTextColor() { if (!IsStop) { if (DarkText) { Loading @@ -179,9 +222,11 @@ namespace CountDownList.Controls TimeTextFull.Foreground = Light; } } } public void SyncBackground() { if(!IsStop) bg.Background = LabelBackground; } Loading Loading @@ -221,6 +266,17 @@ namespace CountDownList.Controls MessageBox.Show("在预览模式下无法执行分享操作", Title, MessageBoxButton.OK, MessageBoxImage.Warning, MessageBoxResult.OK, MessageBoxOptions.ServiceNotification); } } public bool IsMouseEnter = false; private void userControl_MouseEnter(object sender, MouseEventArgs e) { IsMouseEnter = true; } private void userControl_MouseLeave(object sender, MouseEventArgs e) { IsMouseEnter = false; } #pragma warning restore CS8602 // 解引用可能出现空引用。 } }
CountDownList/MainWindow.xaml +13 −4 Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:CountDownList" mc:Ignorable="d" RenderOptions.ClearTypeHint="Enabled" xmlns:control="clr-namespace:CountDownList.Controls" xmlns:hc="https://handyorg.github.io/handycontrol" xmlns:local1="clr-namespace:CountDownList.Class" Title="MainWindow" Height="500" Width="392" Background="{x:Null}" ResizeMode="CanMinimize" WindowStyle="None"> Loading Loading @@ -131,19 +132,27 @@ </TransformGroup> </Border.RenderTransform> <Grid Margin="0,4,0,4"> <local:MyScrollViewer VirtualizingStackPanel.IsVirtualizing="True" VirtualizingStackPanel.VirtualizationMode="Standard" VerticalScrollBarVisibility="Hidden"> <local:MyScrollViewer x:Name="sv" VirtualizingStackPanel.IsVirtualizing="True" VirtualizingStackPanel.VirtualizationMode="Standard" VerticalScrollBarVisibility="Hidden"> <local:MyScrollViewer.OpacityMask> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="Transparent"/> <GradientStop Color="Transparent" Offset="1"/> <GradientStop Color="White" Offset="0.02"/> <GradientStop Color="White" Offset="0.98"/> </LinearGradientBrush> </local:MyScrollViewer.OpacityMask> <StackPanel> <Expander x:Name="DoingE" Background="#00F7F7F7" BorderBrush="{x:Null}" IsExpanded="True" Header="进行中(5)" Margin="4,0,4,0" Foreground="#FFF7F7F7"> <Expander RenderOptions.ClearTypeHint="Enabled" x:Name="DoingE" Background="#00F7F7F7" BorderBrush="{x:Null}" IsExpanded="True" Header="进行中(5)" Margin="4,0,4,0" Foreground="#FFF7F7F7"> <StackPanel x:Name="doingList"> </StackPanel> </Expander> <Expander x:Name="countE" Background="#00000000" BorderBrush="{x:Null}" Header="正计时(5)" Margin="4,0,4,0" Foreground="#FFF7F7F7" IsExpanded="True"> <Expander RenderOptions.ClearTypeHint="Enabled" x:Name="countE" Background="#00000000" BorderBrush="{x:Null}" Header="正计时(5)" Margin="4,0,4,0" Foreground="#FFF7F7F7" IsExpanded="True"> <StackPanel x:Name="count"> </StackPanel> </Expander> <Expander x:Name="wcE" Background="#00000000" BorderBrush="{x:Null}" Header="已完成(5)" Margin="4,0,4,0" Foreground="#FFF7F7F7"> <Expander RenderOptions.ClearTypeHint="Enabled" x:Name="wcE" Background="#00000000" BorderBrush="{x:Null}" Header="已完成(5)" Margin="4,0,4,0" Foreground="#FFF7F7F7"> <StackPanel x:Name="wancheng"> </StackPanel> Loading
CountDownList/MainWindow.xaml.cs +9 −7 Original line number Diff line number Diff line Loading @@ -39,18 +39,20 @@ namespace CountDownList zkImageTest.ImageSource = new BitmapImage(new Uri(@"Data\Image\4.jpg", UriKind.Relative)); zkImageTest.Stretch = Stretch.UniformToFill; AddTest("跨年倒计时!",new(2024,1,1),new(2025,1,1), "dd\\天hh\\:mm\\:ss",false, NewYearImageTest); AddTest("2025春节", new(2024, 2, 10), new(2025, 1, 29), "dd\\天hh\\:mm\\:ss", false, NewYearImageTest); AddCount("去年生日", new(2024, 8, 7), "dd\\天hh\\:mm\\:ss", true, BirthImageTest); AddCount("中考", new(2024, 6, 24), "dd\\天hh\\:mm\\:ss", true, zkImageTest); AddTest("明年生日", new(2024, 8, 7), new(2025,8,7), "dd\\天hh\\:mm\\:ss", true, BirthImageTest); DoingE.Header = $"进行中({doingList.Children.Count})"; wcE.Header = $"已完成({wancheng.Children.Count})"; countE.Header = $"正计时({count.Children.Count})"; Core = new(doingList, wancheng, count, DoingE, wcE, countE); Core = new(doingList, wancheng, count, DoingE, wcE, countE,sv); Core.AddCountDownLabel("跨年倒计时!(ListCore生成的)", new(2024, 1, 1), new(2025, 1, 1), "dd\\天hh\\:mm\\:ss", false, NewYearImageTest); Core.AddCountDownLabel("跨年倒计时!", new(2024, 1, 1), new(2025, 1, 1), "dd\\天hh\\:mm\\:ss", false, NewYearImageTest); Core.AddCountDownLabel("2025春节", new(2024, 2, 10), new(2025, 1, 29), "dd\\天hh\\:mm\\:ss", false, NewYearImageTest); Core.AddCountLabel("去年生日", new(2024, 8, 7), "dd\\天hh\\:mm\\:ss", true, BirthImageTest); Core.AddCountLabel("中考", new(2024, 6, 24), "dd\\天hh\\:mm\\:ss", true, zkImageTest); Core.AddCountDownLabel("明年生日", new(2024, 8, 7), new(2025, 8, 7), "dd\\天hh\\:mm\\:ss", true, BirthImageTest); } ImageBrush NewYearImageTest = new(); Loading Loading @@ -211,7 +213,7 @@ namespace CountDownList (byte)new Random(DateTime.Now.Nanosecond).Next(32, 233) ) ); AddTest("一分钟后", DateTime.Now, DateTime.Now.AddMinutes(1), "dd\\天hh\\:mm\\:ss",Convert.ToBoolean(new Random(DateTime.Now.Nanosecond).Next(0, 1)),brush); Core.AddCountDownLabel("一分钟后", DateTime.Now, DateTime.Now.AddMinutes(1), "dd\\天hh\\:mm\\:ss",Convert.ToBoolean(new Random(DateTime.Now.Nanosecond).Next(0, 1)),brush); DoingE.Header = $"进行中({doingList.Children.Count})"; } Loading