Skip to content

Commit

Permalink
Fixes #340 by exposing GroupByAdvanced in Gallery and InRibbonGallery
Browse files Browse the repository at this point in the history
  • Loading branch information
batzen committed Oct 30, 2016
1 parent 82cc0df commit b90ad54
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 23 deletions.
20 changes: 16 additions & 4 deletions Fluent.Ribbon.Showcase/TestContent.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,8 @@
<TextBlock Tag="Group2">3 (G 2)</TextBlock>
</Fluent:InRibbonGallery>

<Fluent:InRibbonGallery MinItemsInDropDownRow="5"
<Fluent:InRibbonGallery Header="Many items"
MinItemsInDropDownRow="5"
MaxItemsInDropDownRow="5"
IsCollapsed="True"
ItemHeight="100"
Expand Down Expand Up @@ -1270,9 +1271,7 @@
<Fluent:RibbonGroupBox Header="With Grouping"
Name="SecondGalleryGroup">

<!--To group items in Gallery (or InRibbonGallery)
you can use GroupBy for simplified grouping method or
use traditional method as in System.Windows.Controls.ListBox -->
<!--To group items in Gallery (or InRibbonGallery) you can use GroupBy for simplified grouping method or use traditional method as in System.Windows.Controls.ListBox -->
<Fluent:InRibbonGallery Name="gallerySampleInRibbonGallery"
MinItemsInRow="1"
MaxItemsInRow="5"
Expand All @@ -1294,6 +1293,19 @@
Groups="Group B" />
</Fluent:InRibbonGallery.Filters>
</Fluent:InRibbonGallery>

<!--To group items in Gallery (or InRibbonGallery) you can use GroupedByAdvanced as an advanced grouping method -->
<Fluent:InRibbonGallery MinItemsInRow="1"
MaxItemsInRow="5"
Icon="Images\Gray.png"
Header="GroupedByAdvanced"
ItemWidth="50"
ItemHeight="18"
ItemsSource="{Binding DataItems}"
ItemTemplate="{DynamicResource middleDataItemTemplate}"
GroupByAdvanced="{Binding GroupByAdvancedSample}"
ResizeMode="Both">
</Fluent:InRibbonGallery>
</Fluent:RibbonGroupBox>

<Fluent:RibbonGroupBox Icon="pack://application:,,,/Fluent.Ribbon.Showcase;component/Images/Default.png"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@ public class GallerySampleDataItemViewModel : ViewModel
/// Gets or sets icon
/// </summary>
public ImageSource Icon { get; set; }

/// <summary>
/// Gets or sets large icon
/// </summary>
public ImageSource IconLarge { get; set; }

/// <summary>
/// Gets or sets text
/// </summary>
public string Text { get; set; }

/// <summary>
/// Gets or sets group name
/// </summary>
Expand Down
4 changes: 4 additions & 0 deletions Fluent.Ribbon.Showcase/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public MainViewModel()
this.PreviewCommand = new RelayCommand<GalleryItem>(Preview);
this.CancelPreviewCommand = new RelayCommand<GalleryItem>(CancelPreview);

this.GroupByAdvancedSample = x => ((GallerySampleDataItemViewModel)x).Text.Substring(0, 1);

this.memoryTimer = new Timer(TimeSpan.FromSeconds(5).TotalMilliseconds);
this.memoryTimer.Elapsed += this.HandleMemoryTimer_Elapsed;
this.memoryTimer.Start();
Expand Down Expand Up @@ -120,6 +122,8 @@ public GallerySampleDataItemViewModel[] DataItems
}
}

public Func<object, string> GroupByAdvancedSample { get; private set; }

public IList<string> ManyItems
{
get { return this.manyItems ?? (this.manyItems = this.GenerateStrings(5000)); }
Expand Down
25 changes: 22 additions & 3 deletions Fluent.Ribbon/Controls/Gallery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
// ReSharper disable once CheckNamespace
namespace Fluent
{
using System;
using Fluent.Internal.KnownBoxes;

// TODO: add TemplatePart's in Gallery (!)
Expand Down Expand Up @@ -89,9 +90,27 @@ public string GroupBy
/// Using a DependencyProperty as the backing store for GroupBy.
/// This enables animation, styling, binding, etc...
/// </summary>
public static readonly DependencyProperty GroupByProperty =
DependencyProperty.Register(nameof(GroupBy), typeof(string), typeof(Gallery),
new PropertyMetadata());
public static readonly DependencyProperty GroupByProperty = DependencyProperty.Register(nameof(GroupBy), typeof(string), typeof(Gallery), new PropertyMetadata());

#endregion

#region GroupByAdvanced

/// <summary>
/// Gets or sets name of property which
/// will use to group items in the Gallery.
/// </summary>
public Func<object, string> GroupByAdvanced
{
get { return (Func<object, string>)this.GetValue(GroupByAdvancedProperty); }
set { this.SetValue(GroupByAdvancedProperty, value); }
}

/// <summary>
/// Using a DependencyProperty as the backing store for GroupBy.
/// This enables animation, styling, binding, etc...
/// </summary>
public static readonly DependencyProperty GroupByAdvancedProperty = DependencyProperty.Register(nameof(GroupByAdvanced), typeof(Func<object, string>), typeof(Gallery), new PropertyMetadata());

#endregion

Expand Down
31 changes: 17 additions & 14 deletions Fluent.Ribbon/Controls/GalleryPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ public class GalleryPanel : StackPanel
// Designate that gallery panel must be refreshed its groups
private bool needsRefresh;

// Group name resolver
private Func<object, string> groupByAdvanced;

#endregion

#region Properties
Expand Down Expand Up @@ -80,9 +77,7 @@ public string GroupBy
/// Using a DependencyProperty as the backing store for GroupBy.
/// This enables animation, styling, binding, etc...
/// </summary>
public static readonly DependencyProperty GroupByProperty =
DependencyProperty.Register(nameof(GroupBy), typeof(string), typeof(GalleryPanel),
new PropertyMetadata(OnGroupByChanged));
public static readonly DependencyProperty GroupByProperty = DependencyProperty.Register(nameof(GroupBy), typeof(string), typeof(GalleryPanel), new PropertyMetadata(OnGroupByChanged));

private static void OnGroupByChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
Expand All @@ -95,17 +90,25 @@ private static void OnGroupByChanged(DependencyObject d, DependencyPropertyChang
#region GroupByAdvanced

/// <summary>
/// Gets or sets custom user method to group items.
/// If this property is not null, GroupBy property is ignored
/// Gets or sets name of property which
/// will use to group items in the Gallery.
/// </summary>
public Func<object, string> GroupByAdvanced
{
get { return this.groupByAdvanced; }
set
{
this.groupByAdvanced = value;
this.Invalidate();
}
get { return (Func<object, string>)this.GetValue(GroupByAdvancedProperty); }
set { this.SetValue(GroupByAdvancedProperty, value); }
}

/// <summary>
/// Using a DependencyProperty as the backing store for GroupBy.
/// This enables animation, styling, binding, etc...
/// </summary>
public static readonly DependencyProperty GroupByAdvancedProperty = DependencyProperty.Register(nameof(GroupByAdvanced), typeof(Func<object, string>), typeof(GalleryPanel), new PropertyMetadata(OnGroupByAdvancedChanged));

private static void OnGroupByAdvancedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var galleryPanel = (GalleryPanel)d;
galleryPanel.Invalidate();
}

#endregion
Expand Down
24 changes: 22 additions & 2 deletions Fluent.Ribbon/Controls/InRibbonGallery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,27 @@ public string GroupBy
/// Using a DependencyProperty as the backing store for GroupBy.
/// This enables animation, styling, binding, etc...
/// </summary>
public static readonly DependencyProperty GroupByProperty =
DependencyProperty.Register(nameof(GroupBy), typeof(string), typeof(InRibbonGallery), new PropertyMetadata());
public static readonly DependencyProperty GroupByProperty = DependencyProperty.Register(nameof(GroupBy), typeof(string), typeof(InRibbonGallery), new PropertyMetadata());

#endregion

#region GroupByAdvanced

/// <summary>
/// Gets or sets name of property which
/// will use to group items in the Gallery.
/// </summary>
public Func<object, string> GroupByAdvanced
{
get { return (Func<object, string>)this.GetValue(GroupByAdvancedProperty); }
set { this.SetValue(GroupByAdvancedProperty, value); }
}

/// <summary>
/// Using a DependencyProperty as the backing store for GroupBy.
/// This enables animation, styling, binding, etc...
/// </summary>
public static readonly DependencyProperty GroupByAdvancedProperty = DependencyProperty.Register(nameof(GroupByAdvanced), typeof(Func<object, string>), typeof(InRibbonGallery), new PropertyMetadata());

#endregion

Expand Down Expand Up @@ -1377,6 +1396,7 @@ public virtual FrameworkElement CreateQuickAccessItem()
var gallery = new InRibbonGallery();
RibbonControl.BindQuickAccessItem(this, gallery);
RibbonControl.Bind(this, gallery, nameof(this.GroupBy), GroupByProperty, BindingMode.OneWay);
RibbonControl.Bind(this, gallery, nameof(this.GroupByAdvanced), GroupByAdvancedProperty, BindingMode.OneWay);
RibbonControl.Bind(this, gallery, nameof(this.ItemHeight), ItemHeightProperty, BindingMode.OneWay);
RibbonControl.Bind(this, gallery, nameof(this.ItemWidth), ItemWidthProperty, BindingMode.OneWay);
RibbonControl.Bind(this, gallery, nameof(this.ResizeMode), ResizeModeProperty, BindingMode.OneWay);
Expand Down
1 change: 1 addition & 0 deletions Fluent.Ribbon/Themes/Controls/Gallery.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@
MaxItemsInRow="{TemplateBinding MaxItemsInRow}"
Filter="{TemplateBinding SelectedFilterGroups}"
GroupBy="{TemplateBinding GroupBy}"
GroupByAdvanced="{TemplateBinding GroupByAdvanced}"
IsItemsHost="True"
ItemHeight="{TemplateBinding ItemHeight}"
ItemWidth="{TemplateBinding ItemWidth}"
Expand Down
1 change: 1 addition & 0 deletions Fluent.Ribbon/Themes/Controls/InRibbonGallery.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@
Orientation="{TemplateBinding Orientation}"
Filter="{TemplateBinding SelectedFilterGroups}"
GroupBy="{TemplateBinding GroupBy}"
GroupByAdvanced="{TemplateBinding GroupByAdvanced}"
IsGrouped="False" />
</ContentControl>
<Image x:Name="PART_FakeImage"
Expand Down

0 comments on commit b90ad54

Please sign in to comment.