diff options
author | Eric Maupin <ermaup@microsoft.com> | 2019-01-24 19:55:17 +0300 |
---|---|---|
committer | Eric Maupin <ermaup@microsoft.com> | 2019-01-24 19:55:19 +0300 |
commit | 9a23598722f9532138341764ede9cb2c1e917412 (patch) | |
tree | 13c5cf9ae0e7c2284f16bd402eef71ee649de0e1 /Xamarin.PropertyEditing.Windows | |
parent | 21c98e48fc25619e7434045acf27c5963037fc77 (diff) |
[Win] Fix uncommon not expanding on search
Fixes #504
Diffstat (limited to 'Xamarin.PropertyEditing.Windows')
4 files changed, 83 insertions, 65 deletions
diff --git a/Xamarin.PropertyEditing.Windows/CategoryExpander.cs b/Xamarin.PropertyEditing.Windows/CategoryExpander.cs index cad9359..e1d6d63 100644 --- a/Xamarin.PropertyEditing.Windows/CategoryExpander.cs +++ b/Xamarin.PropertyEditing.Windows/CategoryExpander.cs @@ -1,36 +1,10 @@ -using System; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; using System.Windows.Input; -using System.Windows.Media; -using Xamarin.PropertyEditing.ViewModels; namespace Xamarin.PropertyEditing.Windows { internal class CategoryExpander - : Expander + : FilterExpander { - public CategoryExpander () - { - DataContextChanged += OnDataContextChanged; - } - - public static readonly DependencyProperty IsFilteredProperty = DependencyProperty.Register ( - "IsFiltered", typeof(bool), typeof(CategoryExpander), new PropertyMetadata (false, (o, args) => ((CategoryExpander)o).OnIsFilteredChanged())); - - public bool IsFiltered - { - get { return (bool) GetValue (IsFilteredProperty); } - set { SetValue (IsFilteredProperty, value); } - } - - public override void OnApplyTemplate () - { - base.OnApplyTemplate (); - UpdateValue(); - } - protected override void OnExpanded () { base.OnExpanded (); @@ -62,58 +36,29 @@ namespace Xamarin.PropertyEditing.Windows base.OnKeyDown (e); } - private bool fromFilter; - private PanelViewModel panelVm; - - private void UpdateValue () + protected override void UpdateValue () { - if (this.panelVm == null) + if (ViewModel == null) return; - SetCurrentValue (IsExpandedProperty, IsFiltered || this.panelVm.GetIsExpanded (Header as string)); + SetCurrentValue (IsExpandedProperty, IsFiltered || ViewModel.GetIsExpanded (Header as string)); } - private void OnIsFilteredChanged () + protected override void OnIsFilteredChanged () { this.fromFilter = true; - UpdateValue (); + base.OnIsFilteredChanged (); this.fromFilter = false; } - private void UpdateViewModel () - { - FrameworkElement element = this; - while (element != null && !(element is ItemsControl)) { - element = VisualTreeHelper.GetParent (element) as FrameworkElement; - } - - if (element == null) { - ClearValue (IsFilteredProperty); - this.panelVm = null; - return; - } - - this.panelVm = element.DataContext as PanelViewModel; - if (this.panelVm == null) - throw new InvalidOperationException ("Couldn't find valid parent"); - - SetBinding (IsFilteredProperty, new Binding (nameof(PanelViewModel.IsFiltering)) { - Source = this.panelVm - }); - } + private bool fromFilter; private void SetExpanded (bool isExpanded) { if (this.fromFilter) return; - this.panelVm.SetIsExpanded ((string) Header, isExpanded); - } - - private void OnDataContextChanged (object sender, DependencyPropertyChangedEventArgs e) - { - UpdateViewModel(); - UpdateValue(); + ViewModel.SetIsExpanded ((string) Header, isExpanded); } } } diff --git a/Xamarin.PropertyEditing.Windows/FilterExpander.cs b/Xamarin.PropertyEditing.Windows/FilterExpander.cs new file mode 100644 index 0000000..b3eb7e4 --- /dev/null +++ b/Xamarin.PropertyEditing.Windows/FilterExpander.cs @@ -0,0 +1,72 @@ +using System; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Media; +using Xamarin.PropertyEditing.ViewModels; + +namespace Xamarin.PropertyEditing.Windows +{ + internal class FilterExpander + : Expander + { + + public static readonly DependencyProperty IsFilteredProperty = DependencyProperty.Register ( + "IsFiltered", typeof (bool), typeof (FilterExpander), new PropertyMetadata (false, (o, args) => ((FilterExpander)o).OnIsFilteredChanged ())); + + public bool IsFiltered + { + get { return (bool)GetValue (IsFilteredProperty); } + set { SetValue (IsFilteredProperty, value); } + } + + public override void OnApplyTemplate () + { + base.OnApplyTemplate (); + UpdateViewModel(); + } + + protected PanelViewModel ViewModel + { + get; + private set; + } + + protected virtual void UpdateValue () + { + if (ViewModel == null) + return; + + SetCurrentValue (IsExpandedProperty, IsFiltered); + } + + protected virtual void OnIsFilteredChanged () + { + UpdateValue (); + } + + private void UpdateViewModel () + { + FrameworkElement element = this; + while (element != null && !(element is ItemsControl)) { + element = VisualTreeHelper.GetParent (element) as FrameworkElement; + } + + if (element == null) { + ClearValue (IsFilteredProperty); + ViewModel = null; + return; + } + + ViewModel = element.DataContext as PanelViewModel; + if (ViewModel == null) + throw new InvalidOperationException ("Couldn't find valid parent"); + + SetBinding (IsFilteredProperty, new Binding (nameof (PanelViewModel.IsFiltering)) { + Source = ViewModel + }); + + UpdateValue(); + } + } +} diff --git a/Xamarin.PropertyEditing.Windows/Themes/PropertyEditorPanelStyle.xaml b/Xamarin.PropertyEditing.Windows/Themes/PropertyEditorPanelStyle.xaml index 6f079bc..7e21ce0 100644 --- a/Xamarin.PropertyEditing.Windows/Themes/PropertyEditorPanelStyle.xaml +++ b/Xamarin.PropertyEditing.Windows/Themes/PropertyEditorPanelStyle.xaml @@ -141,7 +141,7 @@ </ControlTemplate> </ItemsControl.Template> </ItemsControl> - <Expander Grid.Row="1" Visibility="{Binding HasUncommonElements,Converter={StaticResource BoolToVisibilityConverter}}" Style="{StaticResource AdvancedPropertiesExpander}"> + <local:FilterExpander Grid.Row="1" Visibility="{Binding HasUncommonElements,Converter={StaticResource BoolToVisibilityConverter}}" Style="{StaticResource AdvancedPropertiesExpander}" IsExpanded="{Binding UncommonShown,Mode=TwoWay}"> <ItemsControl Grid.Row="0" Style="{StaticResource PropertyListStyle}" ItemsSource="{Binding UncommonEditors,Mode=OneTime}"> <ItemsControl.Template> <ControlTemplate> @@ -149,7 +149,7 @@ </ControlTemplate> </ItemsControl.Template> </ItemsControl> - </Expander> + </local:FilterExpander> </Grid> </local:CategoryExpander> </DataTemplate> diff --git a/Xamarin.PropertyEditing.Windows/Xamarin.PropertyEditing.Windows.csproj b/Xamarin.PropertyEditing.Windows/Xamarin.PropertyEditing.Windows.csproj index 6f259d5..d8f8f6c 100644 --- a/Xamarin.PropertyEditing.Windows/Xamarin.PropertyEditing.Windows.csproj +++ b/Xamarin.PropertyEditing.Windows/Xamarin.PropertyEditing.Windows.csproj @@ -99,6 +99,7 @@ <Compile Include="CurrentColorEditorControl.cs" /> <Compile Include="DoubleToPercentageConverter.cs" /> <Compile Include="DoubleToQuantityConverter.cs" /> + <Compile Include="FilterExpander.cs" /> <Compile Include="HasItemsToVisibilityConverter.cs" /> <Compile Include="InvertedVisibilityConverter.cs" /> <Compile Include="IPropertiesHost.cs" /> |