2

スタックパネル内に 5 つの境界線があり、各境界線の幅はウィンドウ幅/5 です。ウィンドウを最大化すると、各境界線の幅はウィンドウ幅/5 に従ってサイズ変更されます。

コンバーターを試してみましたが、コンバーターがウィンドウのサイズが変更されたことを認識する方法として機能しません。

<Window x:Class="ItemPanelTemplateTest.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <StackPanel Orientation="Horizontal">
        <Border Height="20" Background="Red" Width="105" />
        <Border Height="20" Background="Green" Width="105" />
        <Border Height="20" Background="Yellow" Width="105" />
        <Border Height="20" Background="Blue" Width="105" />
        <Border Height="20" Background="Orange" Width="105" />
    </StackPanel>
</Window>

私はMVVMを使用しているので、コードビハインドには何も書きたくありません。

4

1 に答える 1

3

とは別のコンテナを使用してくださいStackPanel。ここでの最良の候補はGridUniformGridですが、後者の方がタイピングが少なくて済むので、次のようになります。

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <UniformGrid Height="20" Rows="1">
        <Border Background="Red" />
        <Border Background="Green" />
        <Border Background="Yellow" />
        <Border Background="Blue" />
        <Border Background="Orange" />
    </UniformGrid>
</Window>

グリッドはウィンドウに合わせて自動的にサイズ変更され、そのコンテンツのサイズが均一に変更されます。

于 2012-07-21T01:36:41.260 に答える