From 9e1a9c4569cc72e2a1b4976c3a5bf9adcc010328 Mon Sep 17 00:00:00 2001 From: Bastian Schmidt Date: Mon, 2 Apr 2018 16:55:36 +0200 Subject: [PATCH] Fixes #549 by changing inheritance and adding support for templates --- Changelog.md | 3 + Fluent.Ribbon/Controls/RibbonControl.cs | 12 +- Fluent.Ribbon/Controls/RibbonGroupBox.cs | 53 +++-- Fluent.Ribbon/Properties/AssemblyInfo.cs | 1 + .../RibbonGroupBoxHeaderTemplateSelector.cs | 29 +++ .../Themes/Controls/RibbonGroupBox.xaml | 197 +++++++++--------- 6 files changed, 168 insertions(+), 127 deletions(-) create mode 100644 Fluent.Ribbon/TemplateSelectors/RibbonGroupBoxHeaderTemplateSelector.cs diff --git a/Changelog.md b/Changelog.md index d521c1104..5d2b4bf5a 100644 --- a/Changelog.md +++ b/Changelog.md @@ -5,6 +5,8 @@ - [#471](../../issues/471) - **Drop support for .Net 4.0** - [#515](../../issues/515) - Switch to new csproj format and require VS2017 for development - [#545](../../issues/545) - SplitButton.IsChecked is not bound 2 way by default + - Due to [#549](../../issues/549) `RibbonGroupBox.Header` is now of type object and `RibbonGroupBox` now inherits from `HeaderedItemsControl` instead of `ItemsControl`. + Please have a look at the [documentation](http://fluentribbon.github.io/documentation/controls/ribbon-group-box#customizingHeader) for details. - ### Bug fixes - [#535](../../issues/535) - BorderBush on bottom of RibbonTabItem (and Ribbon) @@ -17,6 +19,7 @@ - ### Enhancements - [#533](../../issues/533) - Issue when using templated ribbon items - [#544](../../issues/544) - Add proper DPI support for icons/images aquired through ObjectToImageConverter on .NET 4.6.2 + - [#549](../../issues/549) - Implement RibbonGroupBox header template - [#554](../../issues/554) - No Keytips on templated ribbon items. ## 6.1.0 diff --git a/Fluent.Ribbon/Controls/RibbonControl.cs b/Fluent.Ribbon/Controls/RibbonControl.cs index 3a7b62af2..4ba7f59b1 100644 --- a/Fluent.Ribbon/Controls/RibbonControl.cs +++ b/Fluent.Ribbon/Controls/RibbonControl.cs @@ -356,7 +356,17 @@ public static void BindQuickAccessItem(FrameworkElement source, FrameworkElement if (headeredControl != null) { - Bind(source, element, nameof(IHeaderedControl.Header), HeaderProperty, BindingMode.OneWay); + if (headeredControl is HeaderedItemsControl) + { + Bind(source, element, nameof(HeaderedItemsControl.Header), HeaderedItemsControl.HeaderProperty, BindingMode.OneWay); + Bind(source, element, nameof(HeaderedItemsControl.HeaderStringFormat), HeaderedItemsControl.HeaderStringFormatProperty, BindingMode.OneWay); + Bind(source, element, nameof(HeaderedItemsControl.HeaderTemplate), HeaderedItemsControl.HeaderTemplateProperty, BindingMode.OneWay); + Bind(source, element, nameof(HeaderedItemsControl.HeaderTemplateSelector), HeaderedItemsControl.HeaderTemplateSelectorProperty, BindingMode.OneWay); + } + else + { + Bind(source, element, nameof(IHeaderedControl.Header), HeaderProperty, BindingMode.OneWay); + } if (source.ToolTip != null || BindingOperations.IsDataBound(source, ToolTipProperty)) diff --git a/Fluent.Ribbon/Controls/RibbonGroupBox.cs b/Fluent.Ribbon/Controls/RibbonGroupBox.cs index 71753532d..999dea18b 100644 --- a/Fluent.Ribbon/Controls/RibbonGroupBox.cs +++ b/Fluent.Ribbon/Controls/RibbonGroupBox.cs @@ -24,7 +24,7 @@ namespace Fluent [TemplatePart(Name = "PART_DialogLauncherButton", Type = typeof(Button))] [TemplatePart(Name = "PART_Popup", Type = typeof(Popup))] [TemplatePart(Name = "PART_UpPanel", Type = typeof(Panel))] - public class RibbonGroupBox : ItemsControl, IQuickAccessItemProvider, IDropDownControl, IKeyTipedControl, IHeaderedControl + public class RibbonGroupBox : HeaderedItemsControl, IQuickAccessItemProvider, IDropDownControl, IKeyTipedControl, IHeaderedControl { #region Fields @@ -64,6 +64,31 @@ public string KeyTip #endregion + #region Header-Options + + /// + /// for IsCollapsedHeaderContentPresenter. + /// + public static readonly DependencyProperty IsCollapsedHeaderContentPresenterProperty = DependencyProperty.RegisterAttached("IsCollapsedHeaderContentPresenter", typeof(bool), typeof(RibbonGroupBox), new PropertyMetadata(default(bool))); + + /// + /// Sets the value of . + /// + public static void SetIsCollapsedHeaderContentPresenter(DependencyObject element, bool value) + { + element.SetValue(IsCollapsedHeaderContentPresenterProperty, value); + } + + /// + /// Gets the value of . + /// + public static bool GetIsCollapsedHeaderContentPresenter(DependencyObject element) + { + return (bool)element.GetValue(IsCollapsedHeaderContentPresenterProperty); + } + + #endregion + /// /// Gets drop down popup /// @@ -216,32 +241,6 @@ private void UpdateScalableControlSubscribing(bool registerEvents) #endregion - #region Header - - /// - /// Gets or sets group box header - /// - public string Header - { - get { return (string)this.GetValue(HeaderProperty); } - set { this.SetValue(HeaderProperty, value); } - } - - /// - /// Using a DependencyProperty as the backing store for Header. This enables animation, styling, binding, etc... - /// - public static readonly DependencyProperty HeaderProperty = - DependencyProperty.Register(nameof(Header), typeof(string), typeof(RibbonGroupBox), new PropertyMetadata()); - - object IHeaderedControl.Header - { - get { return this.Header; } - - set { this.Header = (string)value; } - } - - #endregion - #region IsLauncherVisible /// diff --git a/Fluent.Ribbon/Properties/AssemblyInfo.cs b/Fluent.Ribbon/Properties/AssemblyInfo.cs index 2afedd7b5..4c343ef9b 100644 --- a/Fluent.Ribbon/Properties/AssemblyInfo.cs +++ b/Fluent.Ribbon/Properties/AssemblyInfo.cs @@ -11,6 +11,7 @@ [assembly: XmlnsPrefix("urn:fluent-ribbon", "fluent")] [assembly: XmlnsDefinition("urn:fluent-ribbon", "Fluent")] [assembly: XmlnsDefinition("urn:fluent-ribbon", "Fluent.Converters")] +[assembly: XmlnsDefinition("urn:fluent-ribbon", "Fluent.TemplateSelectors")] [assembly: XmlnsDefinition("urn:fluent-ribbon", "Fluent.Metro.Behaviours")] [assembly: InternalsVisibleTo("Fluent.Tests")] \ No newline at end of file diff --git a/Fluent.Ribbon/TemplateSelectors/RibbonGroupBoxHeaderTemplateSelector.cs b/Fluent.Ribbon/TemplateSelectors/RibbonGroupBoxHeaderTemplateSelector.cs new file mode 100644 index 000000000..f20603416 --- /dev/null +++ b/Fluent.Ribbon/TemplateSelectors/RibbonGroupBoxHeaderTemplateSelector.cs @@ -0,0 +1,29 @@ +namespace Fluent.TemplateSelectors +{ + using System.Windows; + using System.Windows.Controls; + + /// + /// for the header of . + /// + public class RibbonGroupBoxHeaderTemplateSelector : DataTemplateSelector + { + /// + /// Gets a static instance of . + /// + public static readonly RibbonGroupBoxHeaderTemplateSelector Instance = new RibbonGroupBoxHeaderTemplateSelector(); + + /// + public override DataTemplate SelectTemplate(object item, DependencyObject container) + { + var element = (FrameworkElement)container; + + if (RibbonGroupBox.GetIsCollapsedHeaderContentPresenter(element)) + { + return (DataTemplate)element.FindResource("Fluent.Ribbon.Templates.RibbonGroupBox.TwoLineHeaderTemplate"); + } + + return (DataTemplate)element.FindResource("Fluent.Ribbon.Templates.RibbonGroupBox.OneLineHeaderTemplate"); + } + } +} \ No newline at end of file diff --git a/Fluent.Ribbon/Themes/Controls/RibbonGroupBox.xaml b/Fluent.Ribbon/Themes/Controls/RibbonGroupBox.xaml index 417583416..4a320b34b 100644 --- a/Fluent.Ribbon/Themes/Controls/RibbonGroupBox.xaml +++ b/Fluent.Ribbon/Themes/Controls/RibbonGroupBox.xaml @@ -4,6 +4,7 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:converters="clr-namespace:Fluent.Converters" + xmlns:templateSelectors="clr-namespace:Fluent.TemplateSelectors" mc:Ignorable="d"> + + + + + + + + + +