From 8941db9cf36ff3d66cc1c0d9537883363de5a34e Mon Sep 17 00:00:00 2001 From: MichaelSmith Date: Fri, 28 Feb 2025 23:31:30 +0800 Subject: [PATCH] Update --- Controls/MetroListBox.cs | 57 +++++++---- DependencyPropertyChain.cs | 16 ++++ MainWindow.xaml | 5 +- MainWindow.xaml.cs | 3 + MetroStyle.xaml | 187 +++++++++++++++++++++---------------- 5 files changed, 171 insertions(+), 97 deletions(-) create mode 100644 DependencyPropertyChain.cs diff --git a/Controls/MetroListBox.cs b/Controls/MetroListBox.cs index 62232f4..292dbec 100644 --- a/Controls/MetroListBox.cs +++ b/Controls/MetroListBox.cs @@ -1,10 +1,12 @@ using Jamesnet.Wpf.Animation; using Jamesnet.Wpf.Controls; +using MaterialDesignColors; using MaterialDesignColors.ColorManipulation; using System; using System.Collections.Generic; using System.Drawing; using System.Linq; +using System.Reflection; using System.Text; using System.Threading.Tasks; using System.Windows; @@ -12,47 +14,70 @@ using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; +using ThemeChange_WPF; using Rectangle = System.Windows.Shapes.Rectangle; namespace CustomWindow_WPF.Controls { internal class MetroListBox : ListBox { - private ValueItem? valueItem; - private Storyboard? storyboard; - private Rectangle? _rectangle; + private ValueItem valueItemX; + private ValueItem valueItemY; + private Storyboard storyboard; public override void OnApplyTemplate() { - Grid grid = (Grid)GetTemplateChild("MetroGrid"); base.OnApplyTemplate(); - InitStoryboard(grid); + + Viewbox viewbox = (Viewbox)GetTemplateChild("PART_MetroViewBox"); + + InitStoryboard(viewbox); + + } static MetroListBox() { DefaultStyleKeyProperty.OverrideMetadata(typeof(MetroListBox), new FrameworkPropertyMetadata(typeof(MetroListBox))); } - private void InitStoryboard(Grid grid) + + private void InitStoryboard(Viewbox viewbox) { - valueItem = new(); + + viewbox.RenderTransform=new TranslateTransform(-80,0); + DependencyProperty[] propertyChainX = new DependencyProperty[] + { + Canvas.RenderTransformProperty, + TranslateTransform.XProperty, + }; + DependencyProperty[] propertyChainY = new DependencyProperty[] + { + Canvas.RenderTransformProperty, + TranslateTransform.YProperty, + + }; storyboard = new(); + valueItemX= new(); + valueItemY= new(); + CreateAnimationFor(storyboard,valueItemX, viewbox, propertyChainX); + + + } + + private void CreateAnimationFor(Storyboard storyboard,ValueItem valueItem,Viewbox viewbox, DependencyProperty[] propertyPath) + { valueItem.Mode = EasingFunctionBaseMode.QuinticEaseInOut; - valueItem.Property = new PropertyPath(Canvas.LeftProperty); + valueItem.Property = new PropertyPath("(0).(1)", propertyPath); valueItem.Duration = new Duration(new TimeSpan(0, 0, 0, 0, 500)); - Storyboard.SetTarget(valueItem, grid); - Storyboard.SetTargetProperty(valueItem,valueItem.Property); - + Storyboard.SetTarget(valueItem, viewbox); + Storyboard.SetTargetProperty(valueItem, valueItem.Property); storyboard.Children.Add(valueItem); } - protected override void OnSelectionChanged(SelectionChangedEventArgs e) { - valueItem = new(); - storyboard = new(); + base.OnSelectionChanged(e); - - valueItem.To = SelectedIndex * 50; + valueItemX.To = SelectedIndex * 80; storyboard.Begin(); } } diff --git a/DependencyPropertyChain.cs b/DependencyPropertyChain.cs new file mode 100644 index 0000000..4bdb835 --- /dev/null +++ b/DependencyPropertyChain.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Controls; +using System.Windows.Media; +using System.Windows; + +namespace ThemeChange_WPF +{ + internal class DependencyPropertyChain + { + + } +} diff --git a/MainWindow.xaml b/MainWindow.xaml index 5e6a0de..62623f4 100644 --- a/MainWindow.xaml +++ b/MainWindow.xaml @@ -13,7 +13,7 @@ VerticalAlignment="Center"> HorizontalAlignment="Center" VerticalAlignment="Center" ItemContainerStyle="{StaticResource MetroItem}" - Style="{StaticResource MaterialDesignListBox}"> + Style="{StaticResource MetroListBox}"> @@ -39,5 +39,6 @@ VerticalAlignment="Center"> - + + diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs index dbf3102..2a2ae09 100644 --- a/MainWindow.xaml.cs +++ b/MainWindow.xaml.cs @@ -19,6 +19,9 @@ public partial class MainWindow : Window public MainWindow() { InitializeComponent(); + } + + } } \ No newline at end of file diff --git a/MetroStyle.xaml b/MetroStyle.xaml index 875db14..79cebd9 100644 --- a/MetroStyle.xaml +++ b/MetroStyle.xaml @@ -1,12 +1,54 @@ - + + + + +