0

ウィンドウが展開されたときに UserControl を垂直方向に展開するのに問題があります。

私の UserControl は現在、ItemsControl の VerticalAlignment="Stretch" プロパティを設定することで正しくストレッチされている ItemsControl 内に配置されています。

次の UserControl を ItemsControl に追加します。

<UserControl MinWidth="930">
     <Grid VerticalAlignment="Stretch" Background="Red">
          <Grid.ColumnDefinitions>
               <ColumnDefinition Width="200" />
               <ColumnDefinition Width="730*" />
          </Grid.ColumnDefinitions>
          <Grid.RowDefinitions>
               <RowDefinition Height="400" />
               <RowDefinition Height="*" />
          </Grid.RowDefinitions>

          <DockPanel Grid.Column="1" Grid.ColumnSpan="1" Grid.RowSpan="2" Grid.Row="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="Pink" LastChildFill="True">

              <ItemsControl Name="itemPanelOverview" Grid.Column="1" Background="Black" Margin="0"/>
         </DockPanel>
     </Grid>
</UserControl>

UserControl は、次のように TabControl 内の ItemsControl で呼び出されます。

<TabItem>
     <TabItem.Header>
          HEADER EG
     </TabItem.Header>

     <ItemsControl Name="contentItems" Grid.ColumnSpan="2" Grid.Column="1" Grid.Row="1" VerticalAlignment="Stretch" Background="Blue">
          <Grid Height="35" Background="{DynamicResource GrayMenuGradient}" >
               <Image Source="..." Stretch="None" />
               <TextBlock Text="{Binding WelcomeMessage}" />
          </Grid>
    </ItemsControl>
</TabItem>

青い背景が正しく伸びていることがわかるので、ItemsControl (contentItems) が期待どおりに伸びているように見えます。

この UserControl の高さは、行定義以外には設定していません。足りないものはありますか?

4

1 に答える 1

2

ここには、少なくとも 2 つの側面があります。

1 つ目は、 内に項目がある場合ItemsControl、各項目は実際には 内にあるItemContainerため、拡張するのはコンテナーです。

を宣言することでコンテナを設計できItemContainerTemplateますItemsControl: http://msdn.microsoft.com/en-us/library/system.windows.controls.itemcontainertemplate.aspx

2 番目の考慮事項はItemsPanelTemplate、アイテムが配置されるパネルのタイプを決定する です。のアイテムがItemsControl使用可能なスペースを埋める能力は、 のタイプと同様にコンテナのタイプに依存しItemContainerます。たとえば、 に を使用するStackPanelと、 はその内容に応じて拡大および縮小するItemsPanelTemplateため、使用可能なスペースがいっぱいになることはありません。StackPanelAは機能するDockPanel可能性がありますが、最後の子のみが使用可能なスペースを埋めるために成長します。おそらくUniformGrid、トリックを行うことができます。

于 2012-10-16T13:47:29.497 に答える