0

私の 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ですか?

4

1 に答える 1

2
<ListBox HorizontalContentAlignment="Stretch"
         .../>
于 2013-08-21T20:54:27.690 に答える