Skip to content

Commit

Permalink
Fixes #838 by using TemplateBinding
Browse files Browse the repository at this point in the history
  • Loading branch information
batzen committed Aug 15, 2020
1 parent f15b383 commit 90e39a0
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 40 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- [#830](../../issues/830) - When a window is set to automatically resize to its content, when its title is set in code, it disappears
- [#834](../../issues/834) - InRibbonGallery resizing issue when changing `Visibility`
- [#837](../../issues/837) - InRibbonGallery Property MinItemsInDropDownRow not considered
- [#838](../../issues/838) - InRibbonGallery changes into DropDownButton after DropDown is opened and closed
- [#840](../../issues/840) - Ribbon does not scroll anymore

## 8.0.0
Expand Down
38 changes: 28 additions & 10 deletions Fluent.Ribbon/Controls/UniformGridWithItemSize.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace Fluent
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using Fluent.Internal;
using Fluent.Internal.KnownBoxes;

Expand All @@ -18,12 +19,33 @@ public class UniformGridWithItemSize : Panel
private int nonCollapsedCount;
private int usedColumns;

/// <summary>
/// Gets or sets panel orientation
/// </summary>
public Orientation Orientation
{
get { return (Orientation)this.GetValue(OrientationProperty); }
set { this.SetValue(OrientationProperty, value); }
}

/// <summary>
/// <see cref="DependencyProperty"/> for <see cref="Orientation"/>.
/// </summary>
public static readonly DependencyProperty OrientationProperty =
DependencyProperty.Register(
nameof(Orientation),
typeof(Orientation),
typeof(UniformGridWithItemSize),
new FrameworkPropertyMetadata(
Orientation.Horizontal,
FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsParentMeasure));

/// <summary>
/// Specifies the number of maximum columns in the grid
/// </summary>
public int MinColumns
{
get => (int)this.GetValue(MinColumnsProperty);
get => this.Orientation == Orientation.Horizontal ? (int)this.GetValue(MinColumnsProperty) : 1;
set => this.SetValue(MinColumnsProperty, value);
}

Expand All @@ -37,7 +59,7 @@ public int MinColumns
typeof(UniformGridWithItemSize),
new FrameworkPropertyMetadata(
IntBoxes.Zero,
FrameworkPropertyMetadataOptions.AffectsMeasure),
FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsParentMeasure),
ValidateMinColumns);

private static bool ValidateMinColumns(object o)
Expand All @@ -50,7 +72,7 @@ private static bool ValidateMinColumns(object o)
/// </summary>
public int MaxColumns
{
get => (int)this.GetValue(MaxColumnsProperty);
get => this.Orientation == Orientation.Horizontal ? (int)this.GetValue(MaxColumnsProperty) : 1;
set => this.SetValue(MaxColumnsProperty, value);
}

Expand All @@ -64,7 +86,7 @@ public int MaxColumns
typeof(UniformGridWithItemSize),
new FrameworkPropertyMetadata(
IntBoxes.Zero,
FrameworkPropertyMetadataOptions.AffectsMeasure),
FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsParentMeasure),
ValidateMaxColumns);

private static bool ValidateMaxColumns(object o)
Expand All @@ -76,7 +98,7 @@ private static bool ValidateMaxColumns(object o)
/// DependencyProperty for <see cref="ItemWidth" /> property.
/// </summary>
public static readonly DependencyProperty ItemWidthProperty = DependencyProperty.Register(
nameof(ItemWidth), typeof(double), typeof(UniformGridWithItemSize), new FrameworkPropertyMetadata(DoubleBoxes.NaN, FrameworkPropertyMetadataOptions.AffectsMeasure));
nameof(ItemWidth), typeof(double), typeof(UniformGridWithItemSize), new FrameworkPropertyMetadata(DoubleBoxes.NaN, FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsParentMeasure));

/// <summary>
/// Specifies the item width.
Expand All @@ -91,7 +113,7 @@ public double ItemWidth
/// DependencyProperty for <see cref="ItemHeight" /> property.
/// </summary>
public static readonly DependencyProperty ItemHeightProperty = DependencyProperty.Register(
nameof(ItemHeight), typeof(double), typeof(UniformGridWithItemSize), new FrameworkPropertyMetadata(DoubleBoxes.NaN, FrameworkPropertyMetadataOptions.AffectsMeasure));
nameof(ItemHeight), typeof(double), typeof(UniformGridWithItemSize), new FrameworkPropertyMetadata(DoubleBoxes.NaN, FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsParentMeasure));

/// <summary>
/// Specifies the item height.
Expand All @@ -116,8 +138,6 @@ public double ItemHeight
/// <returns>Desired size</returns>
protected override Size MeasureOverride(Size constraint)
{
Debug.WriteLine($"MeasureOverride: {constraint}");

this.UpdateComputedValues(this.MaxColumns);

var useDefinedItemWidth = double.IsNaN(this.ItemWidth) == false && DoubleUtil.AreClose(this.ItemWidth, 0) == false;
Expand Down Expand Up @@ -188,8 +208,6 @@ protected override Size MeasureOverride(Size constraint)
/// <param name="arrangeSize">Arrange size</param>
protected override Size ArrangeOverride(Size arrangeSize)
{
Debug.WriteLine($"ArrangeOverride: {arrangeSize}");

var childBounds = new Rect(0, 0, arrangeSize.Width / this.usedColumns, arrangeSize.Height / this.rows);
var xStep = childBounds.Width;
var xBound = arrangeSize.Width;
Expand Down
37 changes: 7 additions & 30 deletions Fluent.Ribbon/Themes/Controls/GalleryGroupContainer.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@
TextTrimming="CharacterEllipsis" />
</Grid>

<ItemsPresenter />
<Fluent:UniformGridWithItemSize IsItemsHost="True"
HorizontalAlignment="Left"
Orientation="{TemplateBinding Orientation}"
MinColumns="{TemplateBinding MinItemsInRow}"
MaxColumns="{TemplateBinding MaxItemsInRow}"
ItemWidth="{TemplateBinding ItemWidth}"
ItemHeight="{TemplateBinding ItemHeight}" />
</DockPanel>
<ControlTemplate.Triggers>
<Trigger Property="IsHeadered"
Expand All @@ -39,41 +45,12 @@
Value="Stretch" />
<Setter Property="Focusable"
Value="False" />
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<Fluent:UniformGridWithItemSize IsItemsHost="True"
HorizontalAlignment="Left"
MinColumns="{Binding MinItemsInRow, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Fluent:GalleryGroupContainer}}}"
MaxColumns="{Binding MaxItemsInRow, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Fluent:GalleryGroupContainer}}}"
ItemWidth="{Binding ItemWidth, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Fluent:GalleryGroupContainer}}}"
ItemHeight="{Binding ItemHeight, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Fluent:GalleryGroupContainer}}}" />
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsHeadered"
Value="False">
<Setter Property="HorizontalAlignment"
Value="Left" />
</Trigger>

<!-- Triggers for different ItemsPanels -->
<Trigger Property="Orientation"
Value="Vertical">
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<Fluent:UniformGridWithItemSize IsItemsHost="True"
HorizontalAlignment="Left"
MinColumns="1"
MaxColumns="1"
ItemWidth="{Binding ItemWidth, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Fluent:GalleryGroupContainer}}}"
ItemHeight="{Binding ItemHeight, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Fluent:GalleryGroupContainer}}}" />
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
</Trigger>
</Style.Triggers>
</Style>

Expand Down

0 comments on commit 90e39a0

Please sign in to comment.