Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RibbonTitleBar.MeasureOverride should not return the constraint parameter value #24

Closed
tbolon opened this issue Nov 24, 2014 · 3 comments
Assignees
Labels
Milestone

Comments

@tbolon
Copy link
Contributor

tbolon commented Nov 24, 2014

Hi,

I am trying to use FluentRibbon in a WPF app which use Caliburn.Micro.

Certainly because of the way caliburn micro (and my code) instanciates my UserControl where my ribbon is defined, the MeasureOverride for the RibbonTitleBar control is called with my entire screen width as constraint.

And because the methods returns the parameter instead of returning the real control dimension, my window's width is set to my entire screen width (instead of just what is needed).

MSDN states that MeasureOverride should return the real minimum size required by the control, and not the constraint size, as it could be interpreted as a required size for the control to be correctly displayed.

I have found a way to get the correct behavior, it requires 2 modifications:

  1. Update MeasureOverride in RibbonTitleBar to return the real size instead of the constraint:
/// <summary>
/// Called to remeasure a control.
/// </summary>
/// <param name="constraint">The maximum size that the method can return.</param>
/// <returns>The size of the control, up to the maximum specified by constraint.</returns>
protected override Size MeasureOverride(Size constraint)
{
    if (this.isAtLeastOneRequiredControlPresent == false)
    {
        return base.MeasureOverride(constraint);
    }

    if (this.IsCollapsed)
    {
        return base.MeasureOverride(constraint);
    }

    var resultSize = constraint;

    if (double.IsPositiveInfinity(resultSize.Width)
        || double.IsPositiveInfinity(resultSize.Height))
    {
        resultSize = base.MeasureOverride(resultSize);
    }

    this.Update(resultSize);

    this.itemsContainer.Measure(this.itemsRect.Size);
    this.headerHolder.Measure(this.headerRect.Size);
    this.quickAccessToolbarHolder.Measure(this.quickAccessToolbarRect.Size);

    // We do not return resultsize anymore, instead we compute the real size required by the controls
    //return resultSize;

    var maxHeight = Math.Max(Math.Max(this.itemsRect.Height, this.headerRect.Height), this.quickAccessToolbarRect.Height);
    var width = this.itemsRect.Width + this.headerRect.Width + this.quickAccessToolbarRect.Width;

    return new Size(width, maxHeight);
}
  1. Update the theme files. The previous change results in the titlebar being centered on the top of the window instead of using all the available space. The RibbonControlTemplate in Ribbon.xaml must be updated to set the Fluent:RibbonTitleBar left aligned. For example in Office2013 theme:
<Fluent:RibbonTitleBar x:Name="PART_RibbonTitleBar"
                        Height="{Binding Path=(Fluent:RibbonProperties.TitleBarHeight), RelativeSource={RelativeSource Self}}"
                        Style="{DynamicResource RibbonTitleBarStyle}"
                        Margin="36,0,113,0"
                        VerticalAlignment="Top"
                        HorizontalAlignment="Left"
                        IsCollapsed="{TemplateBinding IsCollapsed}">

I can submit a PR with this bug, or let you fix this issue by yourself, as you prefer.

Thanks !

@tbolon
Copy link
Contributor Author

tbolon commented Nov 25, 2014

I found how to reproduce this behavior: by default, Caliburn.Micro set Window.SizeToContent to SizeToContent.WidthAndHeight. By default, this value is set to SizeToContent.Manual.

When you use SizeToContent.WidthAndHeight, I suppose the layout manager give the entire screen size as constraints, because the window can grow up.

@batzen batzen self-assigned this Nov 25, 2014
@batzen batzen added this to the 3.2.0 milestone Nov 25, 2014
@batzen
Copy link
Member

batzen commented Nov 27, 2014

Feel free to create a PR. I will add some comments to your commit.

@tbolon
Copy link
Contributor Author

tbolon commented Dec 3, 2014

PR #33 created.

@batzen batzen closed this as completed in fc412e6 Dec 9, 2014
batzen added a commit that referenced this issue Dec 9, 2014
Fix Issue #24 : measureoverride
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants