【发布时间】:2024-01-22 00:55:01
【问题描述】:
我正在向我的应用程序添加一个新窗口。此应用程序包含一个ListBox,其ItemsSource 属性绑定到视图模型对象的ObservableCollection。这是用于渲染视图模型对象的数据模板:
<DataTemplate x:Key="DomainTemplate" DataType="DomainViewModel">
<Border BorderBrush="{Binding Converter={StaticResource BrushConverter}, Path=IsSelected}"
BorderThickness="2"
Margin="5"
Name="SelectedBorder">
<Button Click="SelectDomain_Click"
Content="{Binding Path=Name}"
FontSize="16"
FontWeight="Bold"
Height="60"
IsEnabled="{Binding Path=CurrentSiteIsValid, RelativeSource={RelativeSource AncestorType={x:Type c:DomainPicker}}}"
Margin="5" />
</Border>
</DataTemplate>
我正在使用ListBox 上的HorizontalContentAlignment="Stretch" 设置来使所有Buttons 填充ListBox 的宽度。此外,视图模型对象是从数据库中读取的,并且 Name 属性可以包含最长 80 个字符的任何字符串。
问题是我希望Buttons 的宽度与Button 的宽度相同,如果它直接在窗口上,最长的标题将是。然后ListBox 应该调整自己的大小以包含Button,最后窗口应该调整自己的大小为ListBox。
我怎样才能做到这一点?
【问题讨论】:
-
你的最后一段有点不清楚。您能否发布您现在得到的结果的屏幕截图,以及您想如何更改它?