Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
315
LabelPresenter SizeChanged behaviour on Vista
posted

Hi,

I'm having problems understanding and controling how LabelPresenter's SizeChanged event behave under XP and Vista.

As shown in the code below, I'm attaching a SizeChanged event to the first column's label, and writen the code such that as the first column changes in size, the  second column will expand/shrink to fit the grid.

When I run this on XP, it works fine. However, when I run this on Vista, the SizeChanged event keeps getting invoked, until the second column gets shifted all the way to the right.

I've tried playing around with the values, and I've found out that (only on Vista) if I set the column's width to EXACTLY the same value as specified in the e.NewSize.Width, the event gets invoked again and again. If I set the width to any other value, the function works fine.

Am I missing something here? Why does the control behave differently on XP and Vista?

Please help.

Thanks!

p.s. For those who are about to ask why I did not just use AutoFit, let's just say that AutoFit does not meet my needs, and I need to specify some really complex/specific behaviour. Why? Clients' requests.

p.s.s This is an extension of my previous post: http://forums.infragistics.com/forums/t/7608.aspx, which seems quite unloved. It contains a video which shows this code in action on XP.

 

private void xdgField_FieldLayoutInitialized(object sender, FieldLayoutInitializedEventArgs e)
{
    Style style = new Style(typeof(LabelPresenter));
    EventSetter evSetter = new EventSetter(SizeChangedEvent, new SizeChangedEventHandler(labelSizeChanged));
    style.Setters.Add(evSetter);

    e.FieldLayout.Fields[0].Settings.LabelPresenterStyle = style;
    e.FieldLayout.Fields[1].Settings.AllowResize = false;

}

private bool isResizing = false;
private void labelSizeChanged(object sender, SizeChangedEventArgs e)
{
    if (!isResizing)
    {
        isResizing = true;

        // Shift the right column to accomodate the left
        double totalWidth = xdgField.ActualWidth;
        double leftColumn = e.NewSize.Width;
        double rightColumn = totalWidth - leftColumn;

        if (rightColumn < 0)
        {
            leftColumn += rightColumn;
            rightColumn = 0;
        }

        // Update the new widths
        xdgField.DefaultFieldLayout.Fields[0].Settings.LabelWidth = leftColumn;
        xdgField.DefaultFieldLayout.Fields[1].Settings.LabelWidth = rightColumn;
        isResizing = false;
        e.Handled = true;
    }

}
Parents
No Data
Reply
  • 315
    posted
    bump.
    It'll be nice if someone can verify this or advise me on how to go about with this issue.
Children
No Data