Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 41 additions & 16 deletions Controls/MetroListBox.cs
Original file line number Diff line number Diff line change
@@ -1,58 +1,83 @@
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;
using System.Windows.Controls;
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();
}
}
Expand Down
16 changes: 16 additions & 0 deletions DependencyPropertyChain.cs
Original file line number Diff line number Diff line change
@@ -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
{

}
}
5 changes: 3 additions & 2 deletions MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ VerticalAlignment="Center">
HorizontalAlignment="Center"
VerticalAlignment="Center"
ItemContainerStyle="{StaticResource MetroItem}"
Style="{StaticResource MaterialDesignListBox}">
Style="{StaticResource MetroListBox}">
<controls:MetroListBox.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Columns="4" Rows="4" />
Expand All @@ -39,5 +39,6 @@ VerticalAlignment="Center">
<controls:MetroListBoxItem Background="#000000" />

</controls:MetroListBox>
</StackPanel>

</StackPanel>
</Window>
3 changes: 3 additions & 0 deletions MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public partial class MainWindow : Window
public MainWindow()
{
InitializeComponent();

}


}
}
Loading