我正在向我的应用程序添加一个新窗口。此应用程序包含一个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>
我正在使用 上的HorizontalContentAlignment="Stretch"设置ListBox来使所有Buttons填充的宽度ListBox。此外,视图模型对象是从数据库中读取的,并且 Name 属性中可以包含最多 80 个字符的任何字符串。
问题是我希望 的宽度与具有最长标题Buttons的宽度相同,Button如果它直接在窗口上。然后ListBox应该调整自己的大小以包含它Button,最后窗口应该调整自己的大小ListBox。
我怎样才能使这项工作?