From 66cd4bc6079dc9aae7e30a7f68a90115993f9dc1 Mon Sep 17 00:00:00 2001 From: Peter Townsend Date: Tue, 3 Jan 2017 23:53:34 -0500 Subject: [PATCH 1/7] Prevent the MetroDataGridCheckBox from being toggled by a TAB + SPACE when the cell is supposed to be read only. --- src/MahApps.Metro/MahApps.Metro/Styles/Controls.DataGrid.xaml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/MahApps.Metro/MahApps.Metro/Styles/Controls.DataGrid.xaml b/src/MahApps.Metro/MahApps.Metro/Styles/Controls.DataGrid.xaml index 00c771bc12..59eea8ce1b 100644 --- a/src/MahApps.Metro/MahApps.Metro/Styles/Controls.DataGrid.xaml +++ b/src/MahApps.Metro/MahApps.Metro/Styles/Controls.DataGrid.xaml @@ -17,6 +17,7 @@ + From 29ae1be09cc8c1a32825544a30db5035fa2abbf4 Mon Sep 17 00:00:00 2001 From: Thomas Freudenberg Date: Wed, 4 Jan 2017 21:40:33 +0100 Subject: [PATCH 2/7] StringToVisibilityConverter should handle null like an empty string --- .../Converters/StringToVisibilityConverter.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/MahApps.Metro/MahApps.Metro.Shared/Converters/StringToVisibilityConverter.cs b/src/MahApps.Metro/MahApps.Metro.Shared/Converters/StringToVisibilityConverter.cs index 3dad72b9ff..0bf7f40dcf 100644 --- a/src/MahApps.Metro/MahApps.Metro.Shared/Converters/StringToVisibilityConverter.cs +++ b/src/MahApps.Metro/MahApps.Metro.Shared/Converters/StringToVisibilityConverter.cs @@ -56,13 +56,13 @@ public override object ProvideValue(IServiceProvider serviceProvider) public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { - if (value is string && targetType == typeof (Visibility)) + if ((value == null || value is string) && targetType == typeof (Visibility)) { if (OppositeStringValue) { - return (((string) value).ToLower().Equals(String.Empty)) ? Visibility.Visible : FalseEquivalent; + return string.IsNullOrEmpty((string)value) ? Visibility.Visible : FalseEquivalent; } - return (((string) value).ToLower().Equals(String.Empty)) ? FalseEquivalent : Visibility.Visible; + return string.IsNullOrEmpty((string)value) ? FalseEquivalent : Visibility.Visible; } return value; } From 063b9367f9752cfbe4f7ce8970bab1624b5bf824 Mon Sep 17 00:00:00 2001 From: Jan Karger Date: Thu, 5 Jan 2017 14:23:41 +0100 Subject: [PATCH 3/7] Fix NumericUpDown using UseFloatingWatermark Let the TextBox handle the UseFloatingWatermark stuff and use TemplateBinding for the attached properties UseFloatingWatermark and HasText --- .../MahApps.Metro/Themes/NumericUpDown.xaml | 34 ++----------------- 1 file changed, 2 insertions(+), 32 deletions(-) diff --git a/src/MahApps.Metro/MahApps.Metro/Themes/NumericUpDown.xaml b/src/MahApps.Metro/MahApps.Metro/Themes/NumericUpDown.xaml index dcb1e1897c..1f734141b2 100644 --- a/src/MahApps.Metro/MahApps.Metro/Themes/NumericUpDown.xaml +++ b/src/MahApps.Metro/MahApps.Metro/Themes/NumericUpDown.xaml @@ -45,22 +45,7 @@ - - - - - - - - - - - - - - - - - - - - @@ -190,8 +162,6 @@ - - From d81179215e1df219327277dcec3896afeed477a8 Mon Sep 17 00:00:00 2001 From: Jan Karger Date: Thu, 5 Jan 2017 21:21:31 +0100 Subject: [PATCH 4/7] HamburgerMenu SelectedIndex Fix (#2796) * Fix TargetInvocationException on HamburgerMenu If we set the SelectedIndex on the HamburgerMenu then we get the System.Reflection.TargetInvocationException Now it's possible to set the SelectedIndex/SelectedItem or the SelectedOptionsIndex/SelectedOptionsItem * Add ItemTemplateSelector for menu and option items --- .../ExampleViews/HamburgerMenuSample.xaml | 1 + .../HamburgerMenu/HamburgerMenu.Options.cs | 32 ++++++++++++++-- .../HamburgerMenu/HamburgerMenu.Properties.cs | 37 ++++++++++++++++--- .../Controls/HamburgerMenu/HamburgerMenu.cs | 8 ++++ .../MahApps.Metro/Themes/HamburgerMenu.xaml | 9 ++++- 5 files changed, 77 insertions(+), 10 deletions(-) diff --git a/src/MahApps.Metro.Samples/MahApps.Metro.Demo/MahApps.Metro.Demo.Shared/ExampleViews/HamburgerMenuSample.xaml b/src/MahApps.Metro.Samples/MahApps.Metro.Demo/MahApps.Metro.Demo.Shared/ExampleViews/HamburgerMenuSample.xaml index 4c266b2aa1..b327b5e01a 100644 --- a/src/MahApps.Metro.Samples/MahApps.Metro.Demo/MahApps.Metro.Demo.Shared/ExampleViews/HamburgerMenuSample.xaml +++ b/src/MahApps.Metro.Samples/MahApps.Metro.Demo/MahApps.Metro.Demo.Shared/ExampleViews/HamburgerMenuSample.xaml @@ -51,6 +51,7 @@ public static readonly DependencyProperty OptionsItemTemplateProperty = DependencyProperty.Register(nameof(OptionsItemTemplate), typeof(DataTemplate), typeof(HamburgerMenu), new PropertyMetadata(null)); + /// + /// Identifies the dependency property. + /// + public static readonly DependencyProperty OptionsItemTemplateSelectorProperty = DependencyProperty.Register(nameof(OptionsItemTemplateSelector), typeof(DataTemplateSelector), typeof(HamburgerMenu), new PropertyMetadata(null)); + /// /// Identifies the dependency property. /// public static readonly DependencyProperty OptionsVisibilityProperty = DependencyProperty.Register(nameof(OptionsVisibility), typeof(Visibility), typeof(HamburgerMenu), new PropertyMetadata(Visibility.Visible)); + /// + /// Identifies the dependency property. + /// + public static readonly DependencyProperty SelectedOptionsItemProperty = DependencyProperty.Register(nameof(SelectedOptionsItem), typeof(object), typeof(HamburgerMenu), new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault)); + + /// + /// Identifies the dependency property. + /// + public static readonly DependencyProperty SelectedOptionsIndexProperty = DependencyProperty.Register(nameof(SelectedOptionsIndex), typeof(int), typeof(HamburgerMenu), new FrameworkPropertyMetadata(-1, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault | FrameworkPropertyMetadataOptions.Journal)); + /// /// Gets or sets an object source used to generate the content of the options. /// @@ -42,6 +57,15 @@ public DataTemplate OptionsItemTemplate set { SetValue(OptionsItemTemplateProperty, value); } } + /// + /// Gets or sets the DataTemplateSelector used to display each item in the options. + /// + public DataTemplateSelector OptionsItemTemplateSelector + { + get { return (DataTemplateSelector)GetValue(OptionsItemTemplateSelectorProperty); } + set { SetValue(OptionsItemTemplateSelectorProperty, value); } + } + /// /// Gets the collection used to generate the content of the option list. /// @@ -75,8 +99,8 @@ public Visibility OptionsVisibility /// public object SelectedOptionsItem { - get { return _optionsListView.SelectedItem; } - set { _optionsListView.SelectedItem = value; } + get { return GetValue(SelectedOptionsItemProperty); } + set { SetValue(SelectedOptionsItemProperty, value); } } /// @@ -84,8 +108,8 @@ public object SelectedOptionsItem /// public int SelectedOptionsIndex { - get { return _optionsListView.SelectedIndex; } - set { _optionsListView.SelectedIndex = value; } + get { return (int)GetValue(SelectedOptionsIndexProperty); } + set { SetValue(SelectedOptionsIndexProperty, value); } } } } diff --git a/src/MahApps.Metro/MahApps.Metro.Shared/Controls/HamburgerMenu/HamburgerMenu.Properties.cs b/src/MahApps.Metro/MahApps.Metro.Shared/Controls/HamburgerMenu/HamburgerMenu.Properties.cs index fea0928867..590e042878 100644 --- a/src/MahApps.Metro/MahApps.Metro.Shared/Controls/HamburgerMenu/HamburgerMenu.Properties.cs +++ b/src/MahApps.Metro/MahApps.Metro.Shared/Controls/HamburgerMenu/HamburgerMenu.Properties.cs @@ -50,7 +50,25 @@ public partial class HamburgerMenu /// public static readonly DependencyProperty ItemTemplateProperty = DependencyProperty.Register(nameof(ItemTemplate), typeof(DataTemplate), typeof(HamburgerMenu), new PropertyMetadata(null)); - public static readonly DependencyProperty ContentTransitionProperty = DependencyProperty.Register("ContentTransition", typeof(TransitionType), typeof(HamburgerMenu), new FrameworkPropertyMetadata(TransitionType.Normal)); + /// + /// Identifies the dependency property. + /// + public static readonly DependencyProperty ItemTemplateSelectorProperty = DependencyProperty.Register(nameof(ItemTemplateSelector), typeof(DataTemplateSelector), typeof(HamburgerMenu), new PropertyMetadata(null)); + + /// + /// Identifies the dependency property. + /// + public static readonly DependencyProperty SelectedItemProperty = DependencyProperty.Register(nameof(SelectedItem), typeof(object), typeof(HamburgerMenu), new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault)); + + /// + /// Identifies the dependency property. + /// + public static readonly DependencyProperty SelectedIndexProperty = DependencyProperty.Register(nameof(SelectedIndex), typeof(int), typeof(HamburgerMenu), new FrameworkPropertyMetadata(-1, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault | FrameworkPropertyMetadataOptions.Journal)); + + /// + /// Identifies the dependency property. + /// + public static readonly DependencyProperty ContentTransitionProperty = DependencyProperty.Register(nameof(ContentTransition), typeof(TransitionType), typeof(HamburgerMenu), new FrameworkPropertyMetadata(TransitionType.Normal)); /// /// Gets or sets the width of the pane when it's fully expanded. @@ -124,6 +142,15 @@ public DataTemplate ItemTemplate set { SetValue(ItemTemplateProperty, value); } } + /// + /// Gets or sets the DataTemplateSelector used to display each item. + /// + public DataTemplateSelector ItemTemplateSelector + { + get { return (DataTemplateSelector)GetValue(ItemTemplateSelectorProperty); } + set { SetValue(ItemTemplateSelectorProperty, value); } + } + /// /// Gets the collection used to generate the content of the items list. /// @@ -148,8 +175,8 @@ public ItemCollection Items /// public object SelectedItem { - get { return _buttonsListView.SelectedItem; } - set { _buttonsListView.SelectedItem = value; } + get { return GetValue(SelectedItemProperty); } + set { SetValue(SelectedItemProperty, value); } } /// @@ -157,8 +184,8 @@ public object SelectedItem /// public int SelectedIndex { - get { return _buttonsListView.SelectedIndex; } - set { _buttonsListView.SelectedIndex = value; } + get { return (int)GetValue(SelectedIndexProperty); } + set { SetValue(SelectedIndexProperty, value); } } public TransitionType ContentTransition diff --git a/src/MahApps.Metro/MahApps.Metro.Shared/Controls/HamburgerMenu/HamburgerMenu.cs b/src/MahApps.Metro/MahApps.Metro.Shared/Controls/HamburgerMenu/HamburgerMenu.cs index eba2616e15..261eea12b6 100644 --- a/src/MahApps.Metro/MahApps.Metro.Shared/Controls/HamburgerMenu/HamburgerMenu.cs +++ b/src/MahApps.Metro/MahApps.Metro.Shared/Controls/HamburgerMenu/HamburgerMenu.cs @@ -62,7 +62,15 @@ public override void OnApplyTemplate() _optionsListView.MouseUp += OptionsListView_ItemClick; } + this.Loaded -= HamburgerMenu_Loaded; + this.Loaded += HamburgerMenu_Loaded; + base.OnApplyTemplate(); } + + private void HamburgerMenu_Loaded(object sender, RoutedEventArgs e) + { + this.Content = _buttonsListView?.SelectedItem ?? _optionsListView?.SelectedItem; + } } } diff --git a/src/MahApps.Metro/MahApps.Metro/Themes/HamburgerMenu.xaml b/src/MahApps.Metro/MahApps.Metro/Themes/HamburgerMenu.xaml index 2ddc308cd6..13a113fd3d 100644 --- a/src/MahApps.Metro/MahApps.Metro/Themes/HamburgerMenu.xaml +++ b/src/MahApps.Metro/MahApps.Metro/Themes/HamburgerMenu.xaml @@ -103,11 +103,15 @@ Grid.Row="1" Width="{TemplateBinding OpenPaneLength}" AutomationProperties.Name="Menu items" + ItemTemplateSelector="{TemplateBinding ItemTemplateSelector}" ItemTemplate="{TemplateBinding ItemTemplate}" ItemsSource="{TemplateBinding ItemsSource}" + SelectedIndex="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=SelectedIndex, Mode=TwoWay}" + SelectedItem="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=SelectedItem, Mode=TwoWay}" SelectionMode="Single" Style="{StaticResource HamburgerListBoxStyle}" - TabIndex="1" /> + TabIndex="1"> + @@ -120,8 +124,11 @@ Width="{TemplateBinding OpenPaneLength}" VerticalAlignment="Bottom" AutomationProperties.Name="Option items" + ItemTemplateSelector="{TemplateBinding OptionsItemTemplateSelector}" ItemTemplate="{TemplateBinding OptionsItemTemplate}" ItemsSource="{TemplateBinding OptionsItemsSource}" + SelectedIndex="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=SelectedOptionsIndex, Mode=TwoWay}" + SelectedItem="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=SelectedOptionsItem, Mode=TwoWay}" Style="{StaticResource HamburgerListBoxStyle}" TabIndex="2" /> From ddf1864e9c508ef9ab7935dd89e7595fbb266f92 Mon Sep 17 00:00:00 2001 From: Jan Karger Date: Thu, 5 Jan 2017 22:23:35 +0100 Subject: [PATCH 5/7] Fix #2785 Vailidation tooltips for VS TextBox does not show --- .../MahApps.Metro/Styles/VS/TextBox.xaml | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/MahApps.Metro/MahApps.Metro/Styles/VS/TextBox.xaml b/src/MahApps.Metro/MahApps.Metro/Styles/VS/TextBox.xaml index 1d0ffdd07d..d7afce47e7 100644 --- a/src/MahApps.Metro/MahApps.Metro/Styles/VS/TextBox.xaml +++ b/src/MahApps.Metro/MahApps.Metro/Styles/VS/TextBox.xaml @@ -5,15 +5,18 @@ - -