2012-01-27 7 views
0

スクロールビューアにスクロールビューワを持つウィンドウを持つのは、合計空から無限大までの非常に多くのことができるusecontrolのコレクションです。私は、ウィンドウの高さは、それがオーバーフローしないように、画面の高さに取り付けられるようにしたい、また、私は希望の場合、私はMVVMパターンを使用しているため、背後に使用されていないコード..スクロールビューアを使用した動的な高さ

おかげ

<Window x:Class="FreePIE.GUI.Shells.CurveSettingsView" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     Title="CurveSettingsView" Background="{DynamicResource WindowBackgroundBrush}" SizeToContent="WidthAndHeight" MinHeight="200" MinWidth="200"> 
    <Grid> 
     <Grid.RowDefinitions> 
      <RowDefinition Height="*"/> 
      <RowDefinition Height="Auto"/> 
     </Grid.RowDefinitions> 
     <ScrollViewer> 
      <ItemsControl x:Name="Curves" Grid.Row="0"></ItemsControl> 
     </ScrollViewer> 
     <Button x:Name="AddCurve" Width="150" Grid.Row="1">Add new curve</Button> 
    </Grid> 
</Window> 

答えて

0

私が正しくあなたを理解していれば、あなたはあなたのItemsControlは、すべての利用可能なスペースを取るために、そして何ScrollViewerのは、そのような場合にデフォルトItemsPanelTemplateを交換すべての項目

を見るために必要とされないように、その内容のサイズを変更したいですあなたのItemsControlは、すべての利用可能なスペースを占めるように伸びるコントロールを備えていますhはDockPanelとなります。 ItemsPanelTemplateのデフォルト値はStackPanelで、必要に応じて大きくなります。

<ItemsControl x:Name="Curves" Grid.Row="0"> 

    <!-- ItemsPanelTemplate --> 
    <ItemsControl.ItemsPanel> 
     <ItemsPanelTemplate> 
      <DockPanel /> 
     </ItemsPanelTemplate> 
    </ItemsControl.ItemsPanel> 

    <!-- ItemContainerStyle --> 
    <ItemsControl.ItemContainerStyle> 
     <Style> 
      <Setter Property="DockPanel.Dock" Value="Top" /> 
     </Style> 
    </ItemsControl.ItemContainerStyle> 

</ItemsControl> 

あなたはすべてのアイテムを同じ大きさにしたい場合は、私はUniformGrid代わりのDockPanelを使用して、そしてあなたのコレクション内の項目数にRowsプロパティをバインディングお勧めします。

<ItemsControl x:Name="Curves" Grid.Row="0"> 
    <ItemsControl.ItemsPanel> 
     <ItemsPanelTemplate> 
      <UniformGrid Rows="{Binding 
       RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}, 
       Path=Items.Count}" /> 
     </ItemsPanelTemplate> 
    </ItemsControl.ItemsPanel> 
</ItemsControl> 
+0

私は少し不明であった場合、ノー私はItemsControlにの内容が画面よりも窓が大きく作る場合、ウィンドウは、画面の高さは、その後これ以上取り上げたくない申し訳ありませんが、私はにScrollViewerのが欲しいですitemscontrolの可視部分を制限して、すべてのウィンドウが画面上に表示されるようにしてください... – Anders

関連する問題