2014-03-05 2 views
2

xaml 레이아웃에 대한 도움이 필요합니다.WrapPanel에서 자동 크기 조정이 가능합니까?

나는 내부에 두 개의 요소가있는 Wrapanel을 가지고 있습니다. 왼쪽의 MainGrid는 900 픽셀로 고정해야합니다. 두 번째로, AuxillaryDataScrollViewer는 WrapPanel이 감싸는 경우 최소 650, 최대 100 %를 원합니다. 이것이 가능한가?

는 여기에 지금까지 가지고있는 작업은 다음과 같습니다

<Window x:Class="scratch.MainWindow" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     Title="MainWindow" Height="768" Width="1024"> 
    <Grid> 
     <ScrollViewer> 
      <WrapPanel> 
       <Grid Width="900" Height="800" Background="Bisque"></Grid> 
       <ScrollViewer HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Hidden" Width="650"> 
        <Grid Width="1500" Height="700" Background="Tomato"></Grid> 
       </ScrollViewer> 
      </WrapPanel> 
     </ScrollViewer> 
    </Grid> 
</Window> 

감사합니다!

편집 추가 자세히 :

데이터 입력을하고 오른쪽 패널에서 계산 된 결과를 리얼 타임으로 볼 수 있지만, 그의 연구실에있는 컴퓨터 중 일부는 1280pixels의 능력이하고 싶은 사람들에 너무 폭 클라이언트 결과를 데이터 입력 양식 아래로 줄이기를 원합니다.

+0

두 요소를 나란히 사용 하시겠습니까? – voddy

+0

모니터에 해상도가있는 경우, 그렇지 않으면 랩핑을 원합니다. – safetyOtter

+0

코드를 테스트했는데 예상대로 작동합니다. – voddy

답변

3

요구 사항이 너무 잘 정의되어 있으므로 SizeChanged 처리기를 추가하고 컨테이너 폭 당 수동으로 두 번째 요소의 너비를 설정할 수 있습니다. 컨테이너가 900 + 650 미만인 경우 두 번째 요소를 컨테이너의 100 %까지 늘립니다.

public MainWindow() 
{ 
    SizeChanged += MainWindow_SizeChanged; 
} 

void MainWindow_SizeChanged(object sender, SizeChangedEventArgs e) 
{ 
    double firstElementWidth = MainGrid.Width;       // 900 
    double secondElementMinWidth = AuxillaryDataScrollViewer.MinWidth; // 650 

    double secondElementWidth; 

    // if wrapped, stretch to the container 
    if (e.NewSize.Width < firstElementWidth + secondElementMinWidth) 
     secondElementWidth = e.NewSize.Width; 
    // otherwise (not wrapped), fill the remainder of the first row 
    else 
     secondElementWidth = e.NewSize.Width - firstElementWidth; 
} 

분명히 빠르다. 좀 더 견고한 것이 필요한 경우 필요한 컨벤션을 준수하는 custom panel을 작성하는 것이 좋습니다. WrapPanel은 요소를 전체 너비로 늘릴 수 없지만 패널을 디자인 할 수없는 이유는 없습니다.

+0

나는 이것에 대해 생각했지만 간단하거나 덜 복잡한 해결책을 찾지 못해서 코드 리뷰에서 비웃고 싶지 않았다. 감사! – safetyOtter

관련 문제