【发布时间】:2013-08-24 09:59:22
【问题描述】:
我的 WPF 应用程序包含一个窗口,其中有一个 ListBox。窗口的视图模型包含 ObservableCollection 的 DomainViewModel 对象。
窗口定义如下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" />
当窗口呈现时,每个按钮的宽度都足以显示其 Content 属性中的文本。但这不是我想要的。我希望每个按钮都是ListBox 的宽度,它会随着窗口本身的宽度而变化。
如何让Buttons 保持其宽度设置为ListBox's 宽度?
【问题讨论】: