Nested Scroll Areas

前端 未结 7 576
失恋的感觉
失恋的感觉 2020-12-05 15:34

I creating a control for WPF, and I have a question for you WPF gurus out there.

I want my control to be able to expand to fit a resizable window.

In my con

7条回答
  •  甜味超标
    2020-12-05 16:23

    I used Daniels solution. That works great. Thank you.

    Then I added two boolean dependency properties to the decorator class: KeepWidth and KeepHeight. So the new feature can be suppressed for one dimension.

    This requires a change in MeasureOverride:

    protected override Size MeasureOverride(Size constraint)
    {
        var innerWidth = Math.Min(this._lastArrangeSize.Width, constraint.Width);
        var innerHeight = Math.Min(this._lastArrangeSize.Height, constraint.Height);
        base.MeasureOverride(new Size(innerWidth, innerHeight));
    
        var outerWidth = KeepWidth ? Child.DesiredSize.Width : 0;
        var outerHeight = KeepHeight ? Child.DesiredSize.Height : 0;
        return new Size(outerWidth, outerHeight);
    }
    

提交回复
热议问题