Skip to content

Commit b8caae0

Browse files
committedJan 29, 2019
Finalized grouping implementation, code cleanup
1 parent 6924fb7 commit b8caae0

10 files changed

+169
-337
lines changed
 

‎MHArmory.Core.WPF/Behaviors/DebugLayoutBehavior.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,17 @@ private static void ItemLoaded(object sender, RoutedEventArgs e)
4747
private static void OnAttachedElementLoaded(FrameworkElement item)
4848
{
4949
item.Name = "ROOT";
50-
Go(item);
50+
ListenLayoutChanges(item);
5151
}
5252

53-
private static void Go(DependencyObject item)
53+
private static void ListenLayoutChanges(DependencyObject item)
5454
{
5555
if (item is UIElement element)
5656
element.LayoutUpdated += (s, e) => OnLayoutUpdated(element, s, e);
5757

5858
int childCount = VisualTreeHelper.GetChildrenCount(item);
5959
for (int i = 0; i < childCount; i++)
60-
Go(VisualTreeHelper.GetChild(item, i));
60+
ListenLayoutChanges(VisualTreeHelper.GetChild(item, i));
6161
}
6262

6363
private static void OnLayoutUpdated(UIElement element, object sender, EventArgs e)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using System.Windows;
7+
using System.Windows.Controls;
8+
using System.Windows.Media;
9+
using System.Windows.Threading;
10+
11+
namespace MHArmory.Core.WPF.Behaviors
12+
{
13+
public interface ISelectionChangedViewNotifier
14+
{
15+
Action<object> SelectionChangedHandler { get; set; }
16+
}
17+
18+
public static class SelectionChangedViewNotifierBehavior
19+
{
20+
public static bool GetIsAttached(ItemsControl target)
21+
{
22+
return (bool)target.GetValue(IsAttachedProperty);
23+
}
24+
25+
public static void SetIsAttached(ItemsControl target, bool value)
26+
{
27+
target.SetValue(IsAttachedProperty, value);
28+
}
29+
30+
public static readonly DependencyProperty IsAttachedProperty = DependencyProperty.RegisterAttached(
31+
"IsAttached",
32+
typeof(bool),
33+
typeof(SelectionChangedViewNotifierBehavior),
34+
new PropertyMetadata(OnIsAttachedChanged)
35+
);
36+
37+
private static void OnIsAttachedChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
38+
{
39+
var itemsControl = (ItemsControl)sender;
40+
41+
if ((bool)e.NewValue)
42+
itemsControl.DataContextChanged += ItemsControl_DataContextChanged;
43+
else
44+
itemsControl.DataContextChanged -= ItemsControl_DataContextChanged;
45+
}
46+
47+
private static void ItemsControl_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
48+
{
49+
var itemsControl = (ItemsControl)sender;
50+
var scrollViewer = VisualTreeHelper.GetChild(itemsControl, 0) as ScrollViewer;
51+
52+
if (e.NewValue is ISelectionChangedViewNotifier notifier)
53+
{
54+
notifier.SelectionChangedHandler = (obj) =>
55+
{
56+
if (obj == null)
57+
{
58+
scrollViewer.ScrollToHome();
59+
return;
60+
}
61+
62+
DependencyObject container = itemsControl.ItemContainerGenerator.ContainerFromItem(obj);
63+
64+
if (container == null)
65+
{
66+
scrollViewer.ScrollToHome();
67+
return;
68+
}
69+
70+
if (container is FrameworkElement element)
71+
element.BringIntoView();
72+
};
73+
}
74+
}
75+
}
76+
}

‎MHArmory.Core.WPF/Controls/CustomListBox.cs

-73
This file was deleted.

‎MHArmory.Core.WPF/Controls/CustomScrollViewer.cs

-28
Original file line numberDiff line numberDiff line change
@@ -35,40 +35,12 @@ public static void SetIsScrollEnabled(DependencyObject target, bool value)
3535
new PropertyMetadata(true)
3636
);
3737

38-
//private ScrollBar verticalScrollBar = null;
39-
40-
protected override void OnTemplateChanged(ControlTemplate oldTemplate, ControlTemplate newTemplate)
41-
{
42-
base.OnTemplateChanged(oldTemplate, newTemplate);
43-
44-
//if (newTemplate != null)
45-
//{
46-
// ApplyTemplate();
47-
// object lol = newTemplate.FindName("PART_VerticalScrollBar", this);
48-
// verticalScrollBar = (ScrollBar)lol;
49-
// Console.WriteLine(lol);
50-
//}
51-
}
52-
5338
protected override void OnMouseWheel(MouseWheelEventArgs e)
5439
{
5540
if (GetIsScrollEnabled(TemplatedParent) == false)
5641
e.Handled = true;
5742
else
5843
base.OnMouseWheel(e);
5944
}
60-
61-
protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
62-
{
63-
base.OnPropertyChanged(e);
64-
65-
66-
//if (e.Property.Name.Contains("ScrollBar"))
67-
//{
68-
// Console.WriteLine($"{e.Property.Name}: {e.OldValue} -> {e.NewValue}");
69-
// if (verticalScrollBar != null)
70-
// verticalScrollBar.Visibility = Visibility.Visible;
71-
//}
72-
}
7345
}
7446
}

‎MHArmory.Core.WPF/Panels/CustomVirtualizingStackPanel.cs

-37
This file was deleted.

‎MHArmory.Core.WPF/Panels/GrowOnlyPanel.cs

-40
This file was deleted.

‎MHArmory.Core.WPF/Panels/GrowingOnlyStackPanel.cs

-80
This file was deleted.

‎MHArmory/ViewModels/RootViewModel.cs

-2
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,6 @@ public RootViewModel()
107107
SetupLocalization();
108108

109109
Extensions = new ExtensionSelectorViewModel(this);
110-
111-
SearchResultsViewModel.Initialize();
112110
}
113111

114112
private void SetupLocalization()

0 commit comments

Comments
 (0)