2017-10-04 5 views
0

현재 Column/Row 범위로 미리 계산 된 Item Heights 및 너비 대신 VariableGridView와 비슷한 방식으로 컨트롤을 만들려고합니다. 내용은 높이 항목을 제어합니다. . 컨트롤 너비를 결정하는 열 간격 WIP 샘플 here을 찾을 수 있습니다.UWP Custom Panel은 Panel Childrens 배열 높이 기준으로 크기가 결정됩니다.

현재 유일한 문제는 컨트롤의 초기로드입니다. 컨트롤이 ScrollViewer에 있고 높이가 창/부모의 높이를 초과하면 스크롤하지 않습니다. 아래를 참조

Scrollbar fills the right hand side

을 나는 창 크기를 조정하면 예상대로하지만, 스크롤이 제대로 작동합니다.

You can see here the scrollbar has fixed itself and is the right size for the content of the Panel

보이지 수 있습니다하지만 당신은 오른쪽 측면에 스크롤의 어두운 부분을 보면 당신은 초기로드에 자신을 올바르게 크기가 아니에요 볼 수 있습니다 : 아래를 참조하십시오.

protected override Size MeasureOverride(Size availableSize) { 
    // Need to use this method LimitUnboundedSize as when within a 
    // ScrollViewer an infinite height is supplied within the availableSize 
    var desiredSize = LimitUnboundedSize(availableSize); 
    UpdateColumnOffsets(); 
    foreach (var child in Children) { 
    child.Measure(desiredSize); 
    } 
    return desiredSize; 
} 

private Size LimitUnboundedSize(Size input) { 
    if (Double.IsInfinity(input.Height)) { 
    var scrollViewer = this.FindAscendant<ScrollViewer>(); 
    var contentHeight = scrollViewer.ViewportHeight.Equals(0) 
     ? Window.Current.Bounds.Height : scrollViewer.ViewportHeight; 
    input.Height = (contentHeight >= GetMaxOffset ? contentHeight : 
     GetMaxOffset); 
    } 
    return input; 
} 

를 내 항목을 차지하려고하는 높이를 계산할 수있는 방법 :

은 내가 MeasureOverride 방법 그러나 내가 잘못 뭘하는지 볼 수없는 컨트롤에 실수를 만들고있어 의심 내 컨트롤의 크기를 설정하기 전에?

+0

. 이 문제는 초기화 할 때 무언가를 설정하고 UI 크기를 조정 한 후에 GetMaxOffset이 항상 contentheight보다 훨씬 높기 때문에 발생합니다. 초기화 할 때 GetMaxOffset은 10이지만 그 이후에는 원래대로 되돌아 가지 않습니다. 높이를 무한대로 두지 않는 이유는 무엇입니까? –

+0

불행히도 높이를 무한하게 만들 수는 없지만 무한 할 경우 충돌이 발생합니다. [here] (https://docs.microsoft.com/en-us/windows/uwp/layout/boxpanel-example-custom-panel)에서 인용 - "그러나 패널 자체는 무한대의 크기를 반환 할 수 없습니다. MeasureOverride의 값으로, 레이아웃 중에 예외가 발생합니다. " – jsmyth886

답변

0

나는 내 문제를 해결할 수있었습니다. 준비 전에 내 카드의 배치를 알아야했습니다. 그런 식으로 columnOffsets이 계산되고 최대 열 오프셋에서 패널의 높이를 기준으로 할 수 있습니다.

나는 아직 github에의 REPO 업데이트, 그러나 여기에서 작업이 업데이트 필요가 코드입니다하지 않은 : 나는 차이가 후 앱을 다운로드 볼 수 있습니다

protected override Size ArrangeOverride(Size finalSize) { 
    foreach (var child in Children) { 
    var resizable = child as IArrangeable; 
    resizable?.Arrange(pointDictionary.GetValueOrDefault(resizable.Card)); 
    } 
    return finalSize; 
} 

private double GetMaxOffset { 
    get { return columnOffsetY.Max(); } 
} 

protected override Size MeasureOverride(Size availableSize) { 
    var desiredSize = availableSize; 
    UpdateColumnOffsets(); 
    foreach (var child in Children) { 
    child.Measure(desiredSize); 
    CreateOffsetCache(child); 
    } 

    if (Double.IsPositiveInfinity(desiredSize.Height)) 
    desiredSize.Height = GetMaxOffset; 

    return desiredSize; 

} 

private Dictionary<Card, Point> pointDictionary; 

private void CreateOffsetCache(UIElement child) { 
    var arrangeable = child as IArrangeable; 
    if (arrangeable == null) return; 
    var card = arrangeable.Card; 
    var useColumnOffset = columnOffsetY[card.Column] < columnOffsetY[card.Column + card.ColumnSpan - 1] 
    ? columnOffsetY[card.Column + card.ColumnSpan - 1] : columnOffsetY[card.Column]; 
    var point = new Point(columnOffsetX[card.Column], useColumnOffset); 
    pointDictionary[card] = point; 
    SetColumnOffsetY(card.Column, card.ColumnSpan, child.DesiredSize.Height); 
}