2012-03-18 7 views
1

ラジオボタンテキストを含むラジオボタンを均等にレイアウトする方法はありますか?私はOrientation = Horizo​​ntal、DockPanel、UniformGridでStackPanelを試しましたが、テキストを折り返したり切り捨てたりすることなく、コントロール間の空白が均等になるような正確な外観を実現していません。ラジオボタン偶数水平アラインメント

StackPanel Alignment Horizontal

UniformGrid One Row

<GroupBox Name="grpLegend" Header="{x:Static res:Strings.ChartOptionsDisplayControlView_GroupBox_Legend}"> 
       <ItemsControl 
        ItemsSource="{Binding IsAsync=True, Path=AvailablePitchbookLegendPosition}"> 
        <ItemsControl.ItemTemplate> 
         <DataTemplate> 
          <RadioButton 
           Content="{Binding IsAsync=True, Path=DisplayName}" 
           IsChecked="{Binding IsAsync=True, Path=IsSelected}" 
           GroupName="LegendPosition" 
           Margin="2,3.5" /> 
         </DataTemplate> 
        </ItemsControl.ItemTemplate> 
        <ItemsControl.ItemsPanel> 
         <ItemsPanelTemplate> 
          <StackPanel Orientation="Horizontal"/> 
         </ItemsPanelTemplate> 
        </ItemsControl.ItemsPanel> 
       </ItemsControl> 
      </GroupBox> 

答えて

3
<Grid> 
    <Grid.ColumnDefinitions> 
     <ColumnDefinition Width="Auto"/> 
     <ColumnDefinition/> 
     <ColumnDefinition Width="Auto"/> 
    </Grid.ColumnDefinitions> 

    <RadioButton Grid.Column="0" Content="Left"/> 
    <RadioButton Grid.Column="1" HorizontalAlignment="Center" Content="Center"/> 
    <RadioButton Grid.Column="2" Content="Right"/> 
</Grid> 

このグリッドは、リストのItemTemplateにの一部だったとあなたはSharedSizeGroupプロパティを使用する必要がありますグリッドの列の幅を同期したい場合。

<Grid> 
    <Grid.ColumnDefinitions> 
     <ColumnDefinition Width="Auto" SharedSizeGroup="c1"/> 
     <ColumnDefinition SharedSizeGroup="c2"/> 
     <ColumnDefinition Width="Auto" SharedSizeGroup="c3"/> 
    </Grid.ColumnDefinitions> 

    <RadioButton Grid.Column="0" Content="Left"/> 
    <RadioButton Grid.Column="1" HorizontalAlignment="Center" Content="Center"/> 
    <RadioButton Grid.Column="2" Content="Right"/> 
</Grid> 

は、その後、適切な親コンテナの上にあなたの答えのための添付プロパティのGrid.IsSharedSizeScope = "true" を

<ListBox Grid.IsSharedSizeScope="True" ItemTemplate={StaticResource RadioButtonTemplate}/> 
+0

感謝を使用しています。それは間違いなく静的なアイテムで動作します。私は、これがダイナミックなコレクション、したがって潜在的に可変の数のラジオボタンでどのように機能するのだろうと思っていました。 – dior001

+0

更新された回答。より多くの例については、Grid.IsSharedSizeScopeを参照してください。 – Phil

+0

ありがとう。私はあなたの答えは動作するが、私は正常に私のItemsControlにそれを適用することができていないことを知っている。私はあなたが1つではなく3つのラジオボタンを含むテンプレートにコレクションデータをバインドする方法について混乱しています。私がそれをすると、私は3つではなく9つのラジオボタンを手に入れます。それはXAMLの知識の欠如です。 – dior001