2011-06-30 219 views
1

我有以下XAML駐留在一個WPF用戶控件 -WPF佈局幫助

<Grid>  
     <Grid.RowDefinitions> 
      <RowDefinition Height="30" /> 
      <RowDefinition Height="*" /> 
      <RowDefinition Height="30" /> 
     </Grid.RowDefinitions> 

     <TextBox 
      x:Name="MyTxt" 
      TextWrapping="WrapWithOverflow" 
      Grid.Row="0" 
      /> 

     <ListView     
      x:Name="MyList" 
      ItemsSource="{Binding}" 
      Grid.Row="1" 
      /> 

     <Label 
      Grid.Row="2" 
      /> 
    </Grid> 

該控制是嵌套在視圖中的網格內。我希望文本框的高度位於網格頂部,底部的標籤顯示爲網格底部的固定高度。我想要列表視圖來填充屏幕區域的其餘部分。

我遇到的問題是listview的大小不正確。如果我顯示的記錄太多,它會超出窗口,並且沒有滾動條可用於向下滾動。因此,如果數據伸展到屏幕右側,我無法看到垂直滾動條的底部。

我能夠將listview設置爲一個固定的高度,但工作,但我希望它是更動態和調整窗口如果可能的話。

有沒有人有任何提示,可能會確定正確的大小?

感謝您的任何想法。

編輯 - 這是在主窗口視圖中包含網格的xaml。這是從文章改編的約什 - 史密斯here

<Grid> 
     <Border 
      Style="{StaticResource MainBorderStyle}" 
      > 
      <HeaderedContentControl 
      Content="{Binding Path=Workspaces}" 
      ContentTemplate="{StaticResource WorkspacesTemplate}"     
      /> 
     </Border> 
</Grid> 

我有在下面的一些答案提到設置的ScrollViewer屬性。 下面是DataTemplate中工作區

<DataTemplate x:Key="WorkspacesTemplate"> 
     <TabControl 
     IsSynchronizedWithCurrentItem="True" 
     ItemsSource="{Binding}" 
     ItemTemplate="{StaticResource ClosableTabItemTemplate}" 
     Margin="4" 
     /> 
    </DataTemplate> 
+0

你還可以發佈包含你的UserControl的網格嗎? –

回答

0

我能夠得到它的工作。如果我在主窗口中更改包含網格以使用ContentControl而不是HeaderedcontentControl,它將按預期工作。

感謝您的幫助。

0

你能只是這些屬性添加到列表視圖?

ScrollViewer.CanContentScroll = "True" 
ScrollViewer.VerticalScrollBarVisibility="Visible" <!-- or "Auto" --> 

其他一切看起來都對我好。你有三排,其中兩個是絕對的,另一個是伸展的。你也有第二行的列表視圖,所以它應該與它一起展開。

,如果還是不行,請嘗試在ScrollViewer中

<ScrollViewer> 
    <ListView/> 
</ScrollViewer> 
0

什麼是默認的列表框的VerticalAlignment包裹的ListView?您可能需要將垂直對齊設置爲拉伸。

<ListView     
     x:Name="MyList" 
     ItemsSource="{Binding}" 
     Grid.Row="1" 
     VerticalAlignment="Stretch" 
     />