using System; using System.Linq; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Media.Animation; using System.Windows.Shapes; namespace Wpf.Ui.Extend.Controls; /// /// 设置DataTempate /// /// /// /// /// /// < Path /// VerticalAlignment="Center" /// Data="M21.2575 9.44627V2.38044H22.8083V2.87294C23.9958 2.12794 26.1758 2.16461 27.285 3.37878C27.8333 2.78461 28.5008 2.37877 29.4942 2.37877C30.8275 2.37877 32.365 3.13961 32.4617 4.69294C32.5025 5.84378 32.4875 8.16711 32.5 9.44294H30.965C30.96 8.45627 30.965 6.69794 30.965 5.71127C30.965 5.51877 30.965 5.32544 30.955 5.13377C30.9033 4.40377 30.4683 3.92711 29.8883 3.76711C29.1525 3.56378 28.2767 3.93377 27.9383 4.56711C27.72 4.97461 27.7 5.31211 27.6692 5.77544C27.61 6.66211 27.6517 8.55294 27.6517 9.44211H26.1075C26.1075 8.50377 26.1075 6.60877 26.1075 5.67377C26.1132 5.44061 26.1035 5.20732 26.0783 4.97544C25.9692 4.23794 25.5633 3.86544 24.9558 3.74628C24.1792 3.59461 23.43 3.95211 23.0892 4.49628C22.9212 4.86271 22.8307 5.2599 22.8233 5.66294L22.8083 9.44211L21.2575 9.44627ZM3.68583 7.96169C4.86 7.95669 5.69417 7.11919 5.70667 5.93419C5.72 4.72003 4.865 3.85086 3.66417 3.85086C2.46333 3.85086 1.64167 4.71169 1.66417 5.95336C1.68167 7.15669 2.5 7.96752 3.68583 7.96169ZM7.26917 9.44669H5.73L5.7225 8.59753C5.27225 8.96135 4.74445 9.21691 4.17981 9.34449C3.61517 9.47207 3.02877 9.46826 2.46583 9.33336C1.74 9.16669 1.15833 8.74169 0.715833 8.14086C-0.305 6.76586 -0.215833 4.68669 0.911667 3.42503C2.03917 2.16336 3.97 2.03002 5.72583 3.10752V2.38086H7.2725L7.26917 9.44669ZM16.84 9.43881C14.6783 9.43881 13.18 7.99548 13.1825 5.91215C13.1825 3.85381 14.7367 2.36465 16.86 2.38298C18.9583 2.40048 20.4742 3.86798 20.4917 5.89715C20.5092 7.96048 18.9858 9.43798 16.84 9.43881ZM16.8183 7.99131C18 7.99965 18.8333 7.16631 18.8533 5.97215C18.8758 4.74215 18.0383 3.85715 16.8458 3.85131C15.6533 3.84548 14.7908 4.72881 14.8017 5.94465C14.8133 7.13048 15.655 7.98465 16.8183 7.99131ZM8.80917 0.0214844H10.3592V2.37898H12.3467V3.85732H10.3592C10.3592 3.85732 10.3375 6.13732 10.3592 7.00232C10.3775 7.75232 10.605 7.93482 11.3408 7.96315C11.6508 7.97482 11.9617 7.96315 12.3408 7.96315V9.44482C11.9908 9.43732 10.7817 9.47732 10.1933 9.33398C9.50417 9.17565 9.07333 8.69982 8.91583 8.00648C8.84948 7.72704 8.81399 7.44117 8.81 7.15398C8.80083 4.94482 8.79417 0.241484 8.80917 0.0214844ZM36.9117 7.96169C38.0858 7.95669 38.92 7.11919 38.9325 5.93419C38.9458 4.72003 38.0908 3.85086 36.8908 3.85086C35.6908 3.85086 34.8675 4.71169 34.8908 5.95336C34.9075 7.15669 35.7242 7.96752 36.9117 7.96169ZM40.495 9.44669H38.9558L38.9483 8.59753C38.4981 8.96135 37.9703 9.21691 37.4056 9.34449C36.841 9.47207 36.2546 9.46826 35.6917 9.33336C34.9658 9.16669 34.3842 8.74169 33.9417 8.14086C32.9208 6.76586 33.01 4.68669 34.1375 3.42503C35.265 2.16336 37.1958 2.03002 38.9517 3.10752V2.38086H40.4983L40.495 9.44669ZM42.035 0.0214844H43.5833V2.37898H45.5708V3.85732H43.5833C43.5833 3.85732 43.5617 6.13732 43.5833 7.00232C43.6025 7.75232 43.8333 7.93482 44.565 7.96315C44.875 7.97482 45.1858 7.96315 45.565 7.96315V9.44482C45.2158 9.43732 44.0058 9.47732 43.4175 9.33398C42.7283 9.17565 42.2983 8.69982 42.14 8.00648C42.0736 7.72704 42.0382 7.44117 42.0342 7.15398C42.0267 4.94482 42.0208 0.241484 42.035 0.0214844ZM53.8108 7.96169C54.985 7.95669 55.8192 7.11919 55.8317 5.93419C55.845 4.72003 54.99 3.85086 53.79 3.85086C52.59 3.85086 51.7667 4.71169 51.79 5.95336C51.8067 7.15669 52.6233 7.96753 53.8108 7.96169ZM57.3942 11.92H55.855L55.8475 8.59753C55.3972 8.96135 54.8695 9.21691 54.3048 9.34449C53.7402 9.47207 53.1538 9.46826 52.5908 9.33336C51.865 9.16669 51.2833 8.74169 50.8408 8.14086C49.82 6.76586 49.9092 4.68669 51.0367 3.42503C52.1642 2.16336 54.095 2.03002 55.8508 3.10752V2.38086H57.3975L57.3942 11.92ZM47.0908 2.25022L48.6375 0.673555V0.0185547H47.0908V2.25022ZM48.6375 2.91699L47.0908 4.49366V9.44532H48.6375V2.91699Z" /// Fill="White" /> /// /// /// /// /// /// /// public class RunningLine : ContentControl { public static readonly DependencyProperty LineTemplateProperty = DependencyProperty.Register( nameof(LineTemplate), typeof(DataTemplate), typeof(RunningLine), new PropertyMetadata(default(DataTemplate))); public static readonly DependencyProperty AnimationSpeedProperty = DependencyProperty.Register( nameof(AnimationSpeed), typeof(double), typeof(RunningLine), new PropertyMetadata(0.2d)); public RunningLine() { Loaded += OnLoaded; } public DataTemplate LineTemplate { get => (DataTemplate)GetValue(LineTemplateProperty); set => SetValue(LineTemplateProperty, value); } public double AnimationSpeed { get => (double)GetValue(AnimationSpeedProperty); set => SetValue(AnimationSpeedProperty, value); } private void OnLoaded(object sender, RoutedEventArgs e) { var rootPanel = (ItemsControl)Template.FindName("RootPanel", this); var rootPanelNext = (ItemsControl)Template.FindName("RootPanelNext", this); EvaluatePlaceholders(rootPanel); EvaluatePlaceholders(rootPanelNext); RunAnimation(rootPanel, rootPanelNext); } private void EvaluatePlaceholders(ItemsControl panel) { panel.Items.Add(null); panel.UpdateLayout(); var placeholdersCount = (int)(ActualWidth / panel.ActualWidth); var placeholders = Enumerable.Repeat((string)null, placeholdersCount); foreach (var item in placeholders) panel.Items.Add(item); } private async void RunAnimation(ItemsControl panel, ItemsControl panelNext) { panel.UpdateLayout(); panelNext.UpdateLayout(); var animation = new DoubleAnimation { From = 0, To = -panel.ActualWidth, RepeatBehavior = RepeatBehavior.Forever }; var animationNext = new DoubleAnimation { From = ActualWidth, To = ActualWidth - panel.ActualWidth, RepeatBehavior = RepeatBehavior.Forever }; animation.Duration = TimeSpan.FromMilliseconds((animation.From.Value - animation.To.Value) / AnimationSpeed); animationNext.Duration = TimeSpan.FromMilliseconds((animationNext.From.Value - animationNext.To.Value) / AnimationSpeed); animationNext.BeginTime = TimeSpan.FromMilliseconds(-animationNext.To.Value / AnimationSpeed); panel.BeginAnimation(Canvas.LeftProperty, animation); panelNext.BeginAnimation(Canvas.LeftProperty, animationNext); await Task.Delay(animationNext.BeginTime.Value); panelNext.Visibility = Visibility.Visible; } }