Skip to content

DockHelper.cs: Possible bugs #3

@paulushub

Description

@paulushub

When you dock a pane and try to resize it, it crashes most of the times due a negative width or height:

public static void ComputeSpliterLocation(Popup spliter, Point location, Size size)
{
    if (location.X < 0)
    {
        spliter.HorizontalOffset = 0;
        spliter.Width = size.Width + location.X;
    }
    if (location.Y < 0)
    {
        spliter.VerticalOffset = 0;
        spliter.Height = size.Height + location.Y;
    }
    if (location.X + size.Width > SystemParameters.PrimaryScreenWidth)
        spliter.Width = SystemParameters.PrimaryScreenWidth - location.X;
    if (location.Y + size.Height > SystemParameters.PrimaryScreenHeight)
        spliter.Height = SystemParameters.PrimaryScreenHeight - location.Y;
}

The problem areas are spliter.Width = SystemParameters.PrimaryScreenWidth - location.X; and spliter.Height = SystemParameters.PrimaryScreenHeight - location.Y.

A simple change like below fixes the issue, but it could be better:

public static void ComputeSpliterLocation(Popup spliter, Point location, Size size)
{
    if (location.X < 0)
    {
        spliter.HorizontalOffset = 0;
        spliter.Width = size.Width + location.X;
    }
    if (location.Y < 0)
    {
        spliter.VerticalOffset = 0;
        spliter.Height = size.Height + location.Y;
    }
    if (location.X + size.Width > SystemParameters.PrimaryScreenWidth)
    {
        if ((SystemParameters.PrimaryScreenWidth - location.X) > 0)
        {
            spliter.Width = SystemParameters.PrimaryScreenWidth - location.X;
        }

    }
    if (location.Y + size.Height > SystemParameters.PrimaryScreenHeight)
    {
        if ((SystemParameters.PrimaryScreenHeight - location.Y) > 0)
        {
            spliter.Height = SystemParameters.PrimaryScreenHeight - location.Y;
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions