Skip to content
This repository was archived by the owner on Sep 25, 2024. It is now read-only.

Commit 9a23598

Browse files
author
Eric Maupin
committed
[Win] Fix uncommon not expanding on search
Fixes #504
1 parent 21c98e4 commit 9a23598

File tree

4 files changed

+83
-65
lines changed

4 files changed

+83
-65
lines changed
Lines changed: 8 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,10 @@
1-
using System;
2-
using System.Windows;
3-
using System.Windows.Controls;
4-
using System.Windows.Data;
51
using System.Windows.Input;
6-
using System.Windows.Media;
7-
using Xamarin.PropertyEditing.ViewModels;
82

93
namespace Xamarin.PropertyEditing.Windows
104
{
115
internal class CategoryExpander
12-
: Expander
6+
: FilterExpander
137
{
14-
public CategoryExpander ()
15-
{
16-
DataContextChanged += OnDataContextChanged;
17-
}
18-
19-
public static readonly DependencyProperty IsFilteredProperty = DependencyProperty.Register (
20-
"IsFiltered", typeof(bool), typeof(CategoryExpander), new PropertyMetadata (false, (o, args) => ((CategoryExpander)o).OnIsFilteredChanged()));
21-
22-
public bool IsFiltered
23-
{
24-
get { return (bool) GetValue (IsFilteredProperty); }
25-
set { SetValue (IsFilteredProperty, value); }
26-
}
27-
28-
public override void OnApplyTemplate ()
29-
{
30-
base.OnApplyTemplate ();
31-
UpdateValue();
32-
}
33-
348
protected override void OnExpanded ()
359
{
3610
base.OnExpanded ();
@@ -62,58 +36,29 @@ protected override void OnKeyDown (KeyEventArgs e)
6236
base.OnKeyDown (e);
6337
}
6438

65-
private bool fromFilter;
66-
private PanelViewModel panelVm;
67-
68-
private void UpdateValue ()
39+
protected override void UpdateValue ()
6940
{
70-
if (this.panelVm == null)
41+
if (ViewModel == null)
7142
return;
7243

73-
SetCurrentValue (IsExpandedProperty, IsFiltered || this.panelVm.GetIsExpanded (Header as string));
44+
SetCurrentValue (IsExpandedProperty, IsFiltered || ViewModel.GetIsExpanded (Header as string));
7445
}
7546

76-
private void OnIsFilteredChanged ()
47+
protected override void OnIsFilteredChanged ()
7748
{
7849
this.fromFilter = true;
79-
UpdateValue ();
50+
base.OnIsFilteredChanged ();
8051
this.fromFilter = false;
8152
}
8253

83-
private void UpdateViewModel ()
84-
{
85-
FrameworkElement element = this;
86-
while (element != null && !(element is ItemsControl)) {
87-
element = VisualTreeHelper.GetParent (element) as FrameworkElement;
88-
}
89-
90-
if (element == null) {
91-
ClearValue (IsFilteredProperty);
92-
this.panelVm = null;
93-
return;
94-
}
95-
96-
this.panelVm = element.DataContext as PanelViewModel;
97-
if (this.panelVm == null)
98-
throw new InvalidOperationException ("Couldn't find valid parent");
99-
100-
SetBinding (IsFilteredProperty, new Binding (nameof(PanelViewModel.IsFiltering)) {
101-
Source = this.panelVm
102-
});
103-
}
54+
private bool fromFilter;
10455

10556
private void SetExpanded (bool isExpanded)
10657
{
10758
if (this.fromFilter)
10859
return;
10960

110-
this.panelVm.SetIsExpanded ((string) Header, isExpanded);
111-
}
112-
113-
private void OnDataContextChanged (object sender, DependencyPropertyChangedEventArgs e)
114-
{
115-
UpdateViewModel();
116-
UpdateValue();
61+
ViewModel.SetIsExpanded ((string) Header, isExpanded);
11762
}
11863
}
11964
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
using System;
2+
using System.Windows;
3+
using System.Windows.Controls;
4+
using System.Windows.Data;
5+
using System.Windows.Media;
6+
using Xamarin.PropertyEditing.ViewModels;
7+
8+
namespace Xamarin.PropertyEditing.Windows
9+
{
10+
internal class FilterExpander
11+
: Expander
12+
{
13+
14+
public static readonly DependencyProperty IsFilteredProperty = DependencyProperty.Register (
15+
"IsFiltered", typeof (bool), typeof (FilterExpander), new PropertyMetadata (false, (o, args) => ((FilterExpander)o).OnIsFilteredChanged ()));
16+
17+
public bool IsFiltered
18+
{
19+
get { return (bool)GetValue (IsFilteredProperty); }
20+
set { SetValue (IsFilteredProperty, value); }
21+
}
22+
23+
public override void OnApplyTemplate ()
24+
{
25+
base.OnApplyTemplate ();
26+
UpdateViewModel();
27+
}
28+
29+
protected PanelViewModel ViewModel
30+
{
31+
get;
32+
private set;
33+
}
34+
35+
protected virtual void UpdateValue ()
36+
{
37+
if (ViewModel == null)
38+
return;
39+
40+
SetCurrentValue (IsExpandedProperty, IsFiltered);
41+
}
42+
43+
protected virtual void OnIsFilteredChanged ()
44+
{
45+
UpdateValue ();
46+
}
47+
48+
private void UpdateViewModel ()
49+
{
50+
FrameworkElement element = this;
51+
while (element != null && !(element is ItemsControl)) {
52+
element = VisualTreeHelper.GetParent (element) as FrameworkElement;
53+
}
54+
55+
if (element == null) {
56+
ClearValue (IsFilteredProperty);
57+
ViewModel = null;
58+
return;
59+
}
60+
61+
ViewModel = element.DataContext as PanelViewModel;
62+
if (ViewModel == null)
63+
throw new InvalidOperationException ("Couldn't find valid parent");
64+
65+
SetBinding (IsFilteredProperty, new Binding (nameof (PanelViewModel.IsFiltering)) {
66+
Source = ViewModel
67+
});
68+
69+
UpdateValue();
70+
}
71+
}
72+
}

Xamarin.PropertyEditing.Windows/Themes/PropertyEditorPanelStyle.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,15 +141,15 @@
141141
</ControlTemplate>
142142
</ItemsControl.Template>
143143
</ItemsControl>
144-
<Expander Grid.Row="1" Visibility="{Binding HasUncommonElements,Converter={StaticResource BoolToVisibilityConverter}}" Style="{StaticResource AdvancedPropertiesExpander}">
144+
<local:FilterExpander Grid.Row="1" Visibility="{Binding HasUncommonElements,Converter={StaticResource BoolToVisibilityConverter}}" Style="{StaticResource AdvancedPropertiesExpander}" IsExpanded="{Binding UncommonShown,Mode=TwoWay}">
145145
<ItemsControl Grid.Row="0" Style="{StaticResource PropertyListStyle}" ItemsSource="{Binding UncommonEditors,Mode=OneTime}">
146146
<ItemsControl.Template>
147147
<ControlTemplate>
148148
<ItemsPresenter />
149149
</ControlTemplate>
150150
</ItemsControl.Template>
151151
</ItemsControl>
152-
</Expander>
152+
</local:FilterExpander>
153153
</Grid>
154154
</local:CategoryExpander>
155155
</DataTemplate>

Xamarin.PropertyEditing.Windows/Xamarin.PropertyEditing.Windows.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999
<Compile Include="CurrentColorEditorControl.cs" />
100100
<Compile Include="DoubleToPercentageConverter.cs" />
101101
<Compile Include="DoubleToQuantityConverter.cs" />
102+
<Compile Include="FilterExpander.cs" />
102103
<Compile Include="HasItemsToVisibilityConverter.cs" />
103104
<Compile Include="InvertedVisibilityConverter.cs" />
104105
<Compile Include="IPropertiesHost.cs" />

0 commit comments

Comments
 (0)