2016-12-04 4 views
0

私は以下のCntrolTemplateを持っています。このCntrolTemplateには、私が持っているカスタムDataTypeを表示するHierarchicalDataTemplateがあります。 Buttonといくつかのテキストを表示するstackPanelを持つItemsControlです。ItemsControlは次の行に項目をラップしません

私が午前問題は、コンテンツがラップアラウンドし、アイテムの多くが追加されたとき、次の行に移動しないということである。

<ControlTemplate x:Key="MyControlTemplate"> 
    <StackPanel x:Name="MyStackPanel" Orientation="Horizontal" Width="Auto" Margin="0,1,0,1" Background="{x:Null}"> 
     <ItemsControl x:Name="MyItemsControl" Margin="5,0,5,0" ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:MyClass}}, Path=ItemsSource}"> 
      <ItemsControl.ItemsPanel> 
       <ItemsPanelTemplate> 
        <StackPanel Orientation="Horizontal" IsItemsHost="True"> 
         <StackPanel.Resources> 
          <BooleanToVisibilityConverter x:Key="BoolToVisibility"/> 
          <HierarchicalDataTemplate DataType="{x:Type local:MyCustomDataType}"> 
           <Button Height="24" MinWidth="16" Width="Auto" Command="{Binding}" Visibility="{Binding RelativeSource={RelativeSource Self}, Path=IsEnabled, Converter={StaticResource BoolToVisibility}}"           
             Background="Transparent" BorderBrush="Transparent"> 
            <StackPanel Orientation="Horizontal" Height="22" VerticalAlignment="Center"> 
             <Image Height="Auto" Width="Auto" Stretch="Uniform" Source="{Binding Path=IconSource}" 
               Visibility="{Binding Path=HideInTileGroup, Converter={StaticResource BoolToVisibility}}" Margin="2" VerticalAlignment="Center"/> 
             <TextBlock Text="{Binding Path=DisplayName}" VerticalAlignment="Center" Width="Auto" 
                Foreground="{Binding Path=DisplayBrush}" 
                Visibility="{Binding Path=ShowDisplayName, Converter={StaticResource BoolToVisibility}}" FontSize="12"> 
             </TextBlock> 
            </StackPanel> 
           </Button> 
          </HierarchicalDataTemplate> 
         </StackPanel.Resources> 
        </StackPanel> 
       </ItemsPanelTemplate> 
      </ItemsControl.ItemsPanel> 
     </ItemsControl> 
    </StackPanel> 
</ControlTemplate> 

は、どのように私はそれがラップアラウンドすることができますか?

編集:私はそうのようWrapPanelにそれを変更したが、まだそれは折り返されません

<ControlTemplate x:Key="MyControlTemplate"> 
<StackPanel x:Name="MyStackPanel" Orientation="Horizontal" Width="Auto" Margin="0,1,0,1" Background="{x:Null}"> 
    <ItemsControl x:Name="MyItemsControl" Margin="5,0,5,0" ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:MyClass}}, Path=ItemsSource}"> 
     <ItemsControl.ItemsPanel> 
      <ItemsPanelTemplate> 
       <WrapPanel> 
        <WrapPanel.Resources> 
         <BooleanToVisibilityConverter x:Key="BoolToVisibility"/> 
         <HierarchicalDataTemplate DataType="{x:Type local:MyCustomDataType}"> 
          <Button Height="24" MinWidth="16" Width="Auto" Command="{Binding}" Visibility="{Binding RelativeSource={RelativeSource Self}, Path=IsEnabled, Converter={StaticResource BoolToVisibility}}"           
            Background="Transparent" BorderBrush="Transparent"> 
           <StackPanel Orientation="Horizontal" Height="22" VerticalAlignment="Center"> 
            <Image Height="Auto" Width="Auto" Stretch="Uniform" Source="{Binding Path=IconSource}" 
              Visibility="{Binding Path=HideInTileGroup, Converter={StaticResource BoolToVisibility}}" Margin="2" VerticalAlignment="Center"/> 
            <TextBlock Text="{Binding Path=DisplayName}" VerticalAlignment="Center" Width="Auto" 
               Foreground="{Binding Path=DisplayBrush}" 
               Visibility="{Binding Path=ShowDisplayName, Converter={StaticResource BoolToVisibility}}" FontSize="12"> 
            </TextBlock> 
           </StackPanel> 
          </Button> 
         </HierarchicalDataTemplate> 
        </WrapPanel.Resources>        
       </WrapPanel> 
      </ItemsPanelTemplate> 
     </ItemsControl.ItemsPanel> 
    </ItemsControl> 
</StackPanel> 

+0

StackPanelの代わりにWrapPanelを使用しますか? – Clemens

+0

私の外側のStackPanelはWrapPanelですか?内側のItemsControlを同じに保ちますか? –

+0

私はItemsPanelを意味します。 – Clemens

答えて

1

WrapPanelItemsPanelを変更すると、あなたはまだ外StackPanelを持っているからだと、働いていない場合:

<ControlTemplate x:Key="MyControlTemplate"> 
    <StackPanel x:Name="MyStackPanel" Orientation="Horizontal" Width="Auto" Margin="0,1,0,1" Background="{x:Null}"> 

これはItemsPanelはまだそれが無限の幅を持っていると考えていることを意味それに対処するために実際にはラップされません。

外側のStackPanelを完全に取り外してください。他の容器に交換するか、幅を制限してください。あなたのコードには、外側のコンテナが必要なので私に言うことは何もないので、単にそれを削除してそこから移動します。

まだラッピングされていない場合は、ビジュアルツリーのどこかに別の「無限の幅」(つまり内容に合わせて伸びるもの)のコンテナが必要です。あなたは、あなたがそれを見つけるまでこのアイテムから外向きに作業する必要があります。

+0

外側のスタックパネルの幅と高さを800に設定し、それをラップしません。幅800に収まるイメージの数を制限します。外側のスタックパネルも削除しましたが、それでもラップしません。それを別の容器と交換する必要がありますか? –

+1

@ HarryBoy私はあなたが投稿したコードから少なくとも別のコンテナに置き換える必要はないと言いたいと思います。あなたが表示するいくつかの "もの"になる場合は、コンテナが必要です。まだラッピングされていない場合は、ビジュアルツリーのどこかに別の「無限の幅」(つまり内容に合わせて成長するもの)のコンテナが必要です。 – ChrisF

関連する問題