2009-11-02 4 views
0

높이의 데이터 바인딩을 수행하려고하는 ScrollViewer가 있습니다. ScrollViewer에는 긴 ListBox가 있습니다.WPF 높이 데이터 바인딩 질문

여기 내 질문이 있습니다. 내 ScrollViewer 내 윈도우 (Name="MainForm")의 높이에 바인딩됩니다. 하지만 너무 길어.

창 (Name="MainGrid")의 눈금에 바인딩하려고하면 ScrollViewer가 목록 상자의 전체 길이 (스크롤하지 않음)로 확장됩니다.

분명히 높이를 하드 코딩 할 수 있지만 창 크기가 조정되지는 않습니다. 내가 놓치고 싶지 않은 기능.

어떤 아이디어? StackPanel의 성장 때문에

는 MainGrid

에 바인딩 세트로 XAML
<Window 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
Title="WI Assistant" Height="621.25" Width="943.75" Name="MainForm" FontSize="14"> 
<Grid Name="MainGrid"> 
    <DockPanel Margin="266.25,0,455,12" HorizontalAlignment="Left" Name="dockPanel1"> 
     <StackPanel> 
      <ScrollViewer Height="{Binding ElementName=MainGrid, Path=Height}"> 
        <ListBox Name="cboProjects" FontSize="14" > 
        <ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem> 
        <ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem> 
        <ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem> 
        <ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem> 
        <ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem> 
        <ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem> 
        <ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem> 
        <ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem> 
        <ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem> 
        <ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem> 
        <ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem> 
        <ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem> 
        <ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem> 
        <ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem> 
        <ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem> 
        <ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem> 
        <ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem> 
        <ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem> 
        <ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem> 
        <ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem> 
        <ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem> 
        <ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem> 
        <ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem> <ListBoxItem>Test1</ListBoxItem> 
       </ListBox> 
      </ScrollViewer> 
     </StackPanel> 
    </DockPanel> 
</Grid> 

(이 실행됩니다 XamlPadx에서 (F5))

답변

3

StackPanel에서 그것을 가지고있다 방향 (수직 방향,이 경우)의 방향으로 제한되지 않습니다. 가능한 가장 단순한 솔루션으로 시작하십시오.

<Window> 
    <ScrollViewer> 
     <ItemsControl> 
      ... 
     </ItemsControl> 
    </ScrollViewer> 
</Window> 

그런 다음 필요에 따라 복잡성을 추가하십시오.

+1

+1 단일 요소와 함께 'StackPanel'을 사용하면 이러한 질문이 자주 발생하는 경향이 있습니다. –

+0

당신을 축복하십시오! 나는이 머리카락을 내 머리카락으로부터 꺼내려고했다. 그건 그렇고, 나는 Stackpanel을 사용하여 Expanders (두 개 이상의 컨트롤)를 스택했다. 게시하기 전에 Xaml을 단순화했습니다. 이제 스택 패널 내부의 확장기 내부에서 ListBox를 사용할 수 없다는 것을 알고 있습니다. 감사! – Vaccano

+0

또는 실제로, StackPanel (Expanders aside) 내부의 ListBox – Vaccano