0
我的WPF应用程序包含一个窗口,其中包含一个单独的ListBox
。该窗口的查看模型包含ObservableCollection
的DomainViewModel
对象。如何使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
宽度?
这样做了!谢谢! –