2016-05-20 1 views
-2

ItemsPanelをItemsPanelTemplateとして持つItemsControlがあります。私は各ボタンが左右に同じマージンを持つようにボタンのコレクションを整理しようとしています。ここで私が持っているコードは、これまでのところです:ラップパネル内の各アイテムの余白が同じであることを確認するにはどうすればよいですか?

<ScrollViewer HorizontalAlignment="Stretch" VerticalScrollBarVisibility="Auto" CanContentScroll="True"> 
      <ItemsControl HorizontalAlignment="Stretch" ItemsSource="{Binding SystemData.PlayersList}"> 
       <ItemsControl.ItemsPanel> 
        <ItemsPanelTemplate> 
         <WrapPanel/> 
        </ItemsPanelTemplate> 
       </ItemsControl.ItemsPanel> 
       <ItemsControl.ItemTemplate> 
        <DataTemplate> 
         <Border BorderThickness="1" BorderBrush="Gray" Margin="5"> 
          <Button Width="180" 
         Style="{Styles:MyStyleRef ResourceKey=BrowserItemStyle}"> 
           <DockPanel LastChildFill="True"> 
            <Image Source="{Binding Icon}" Style="{Styles:MyStyleRef ResourceKey=DriveImageStyle}"/> 
            <Label HorizontalAlignment="Left" Content="{Binding Name}" Style="{Styles:MyStyleRef ResourceKey=DriveLabelStyle}"/> 
           </DockPanel> 
          </Button> 
         </Border> 
        </DataTemplate> 
       </ItemsControl.ItemTemplate> 
      </ItemsControl> 
     </ScrollViewer> 

そして、ここではそれがどのように見えるかです:

enter image description here

私が行く」にWrapPanelのたHorizo​​ntalAlignmentを設定すると、私は私が望む結果に近づきます。

enter image description here

それはコントロールの均一なグリッドを作成するように私はそれの同じマージンのどちらかの側を持つように各項目を希望 - これは可能ですか?

よろしくお願いします。

答えて

0

これで解決しました...私は完全に均一なグリッドコントロールを見ました。ここで

は私のコードは以下のようになります。

<ScrollViewer HorizontalAlignment="Stretch" VerticalScrollBarVisibility="Auto" CanContentScroll="True"> 
       <ItemsControl HorizontalAlignment="Stretch" VerticalAlignment="Top" ItemsSource="{Binding SystemData.PlayersList}"> 
        <ItemsControl.ItemsPanel> 
         <ItemsPanelTemplate> 
          <UniformGrid Columns="6"/> 
         </ItemsPanelTemplate> 
        </ItemsControl.ItemsPanel> 
        <ItemsControl.ItemTemplate> 
         <DataTemplate> 
          <Border BorderThickness="1" BorderBrush="Gray" Margin="5" Height="40"> 
           <Button 
          Style="{Styles:MyStyleRef ResourceKey=BrowserItemStyle}"> 
            <DockPanel LastChildFill="True"> 
             <Image Source="{Binding Icon}" Style="{Styles:MyStyleRef ResourceKey=DriveImageStyle}"/> 
             <Label HorizontalAlignment="Left" Content="{Binding Name}" Style="{Styles:MyStyleRef ResourceKey=DriveLabelStyle}"/> 
            </DockPanel> 
           </Button> 
          </Border> 
         </DataTemplate> 
        </ItemsControl.ItemTemplate> 
       </ItemsControl> 
      </ScrollViewer> 

enter image description here

関連する問題