2013-08-21 57 views
0

我的WPF应用程序包含一个窗口,其中包含一个单独的ListBox。该窗口的查看模型包含ObservableCollectionDomainViewModel对象。如何使ListBox中的按钮具有相同的宽度

窗口定义了以下DataTemplate

<DataTemplate x:Key="DomainTemplate" DataType="DomainViewModel"> 
    <Border BorderBrush="{Binding Converter={StaticResource BrushConverter}, Path=IsSelected}" 
      BorderThickness="2" 
      Name="SelectedBorder"> 
     <Button Click="SelectDomain_Click" 
       Content="{Binding Path=Name}" 
       FontSize="16" 
       FontWeight="Bold" 
       Height="60" 
       HorizontalAlignment="Stretch" /> 
    </Border> 
</DataTemplate> 

而这里的ListBox的声明:

<ListBox FontSize="16" 
     FontWeight="Bold" 
     Grid.Row="2" 
     ItemsSource="{Binding Path=Domains}" 
     ItemTemplate="{StaticResource DomainTemplate}" 
     Name="DomainListBox" /> 

当窗口呈现,每个按钮是完全足够宽,在显示文字的内容属性。但那不是我想要的。我希望每个按钮的宽度都是ListBox,这将随窗口本身的宽度而变化。

如何获得Buttons以将宽度设置为ListBox's宽度?

回答

2
<ListBox HorizontalContentAlignment="Stretch" 
     .../> 
+0

这样做了!谢谢! –

相关问题