1

リストボックスにいくつかの項目を追加した後でも、リストボックスを行の標準の高さにするにはどうすればよいですか? どちらにも高さを設定したくありません。いくつかの共有サイズグループを設定しようとしたり、各行の高さを別の行にバインドしようとしたりしましたが、解決策はありません。リストボックスが占める4行の高さを元の高さと同じにしたい。現在、リストボックスはその中のすべてのアイテムに合わせて拡大しているため、行が高くなり、これは望ましくありません。リストボックスが4つの「通常の」行の高さよりも高い場合、スクロールバーを取得するだけです。リストボックスに maxHeight を設定する必要がある場合、他の行の高さの 4 倍になるようにするにはどうすればよいですか?

XAML:

<Window x:Class="SharedSizes.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">
<Border Margin="10" >
    <StackPanel Grid.IsSharedSizeScope="True">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" SharedSizeGroup="A"/>
                <ColumnDefinition Width="Auto" SharedSizeGroup="B"/>
                <ColumnDefinition Width="Auto" SharedSizeGroup="C"/>
                <ColumnDefinition Width="Auto" SharedSizeGroup="D"/>
                <ColumnDefinition Width="Auto" SharedSizeGroup="E"/>
                <ColumnDefinition Width="Auto" SharedSizeGroup="F"/>

            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition  Name="Row1" Height="Auto" SharedSizeGroup="Width"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>

            <!--Left Side Parts-->

            <Label Content="Vendor:" Grid.Row="0" Grid.Column="0"/>
            <ComboBox Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="4" />

            <Label Content="Billing Model:" Grid.Row="1" Grid.Column="0" />
            <ComboBox Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2" Width="125"/>

            <Label Content="Billing Cycle:" Grid.Row="2" Grid.Column="0"/>
            <ComboBox Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="2" />

            <StackPanel Grid.Row="2" Grid.Column="3" Orientation="Horizontal" HorizontalAlignment="Left">
                <Button Content="1"/>
                <Button Content="2"/>
                <Button Content="3"/>
                <Button  Content="4"/>
            </StackPanel>
            <Label Content="Clients" Grid.Row="2" Grid.Column="5"/>
        </Grid>
        <Grid>
            <Grid.RowDefinitions>
                <!--<RowDefinition Height="{Binding ElementName=Row1, Path=ActualHeight}"/>
                <RowDefinition Height="{Binding ElementName=Row1, Path=ActualHeight}" />
                <RowDefinition Height="{Binding ElementName=Row1, Path=ActualHeight}" />
                <RowDefinition Height="{Binding ElementName=Row1, Path=ActualHeight}" />-->
                <RowDefinition SharedSizeGroup="Width"/>
                <RowDefinition SharedSizeGroup="Width"/>
                <RowDefinition SharedSizeGroup="Width"/>
                <RowDefinition  SharedSizeGroup="Width"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" SharedSizeGroup="A"/>
                <ColumnDefinition Width="Auto" SharedSizeGroup="B"/>
                <ColumnDefinition Width="Auto" SharedSizeGroup="C"/>
                <ColumnDefinition Width="Auto" SharedSizeGroup="D"/>
                <ColumnDefinition Width="Auto"  />
                <ColumnDefinition  />
            </Grid.ColumnDefinitions>

            <Label Content="Fred" Grid.Row="0"/>
            <Label Content="Fred" Grid.Row="0" Grid.Column="1"/>
            <Label Content="Fred" Grid.Row="0" Grid.Column="2"/>
            <Label Content="Fred" Grid.Row="0" Grid.Column="3"/>
            <Label Content="Fred" Grid.Row="0" Grid.Column="4"/>
            <Label Content="Fred" Grid.Row="1"/>
            <Label Content="Fred" Grid.Row="2"/>
            <Label Content="Fred" Grid.Row="3"/>
            <ListBox Name="FredBox" Grid.Row="0" Grid.Column="5" Grid.RowSpan="4"  Grid.IsSharedSizeScope="True"/>
        </Grid>
    </StackPanel>

常にどのように表示するか(およびリストボックスにアイテムがない場合の方法):

ここに画像の説明を入力

リストボックスにアイテムを追加した後の動作:

ここに画像の説明を入力

VIV の提案のために編集:

<Window x:Class="SharedSizes.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">
<Window.Resources>
    <!--<Style TargetType="{x:Type RowDefinition}">
        <Setter Property="Height" Value="25"/>
    </Style>-->
</Window.Resources>

<Border Margin="10" >
    <StackPanel>
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition  />
                <ColumnDefinition  />
                <ColumnDefinition  />
                <ColumnDefinition  />
                <ColumnDefinition />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition />
                <RowDefinition />
                <RowDefinition />
            </Grid.RowDefinitions>

            <!--Left Side Parts-->

            <Label Content="Vendor:" Grid.Row="0" Grid.Column="0" />
            <ComboBox Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="3" />

            <Label Content="Billing Model:" Grid.Row="1" Grid.Column="0" />
            <ComboBox Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2" />

            <Label Content="Billing Cycle:" Grid.Row="2" Grid.Column="0"/>
            <ComboBox Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="2" />

            <StackPanel Grid.Row="2" Grid.Column="3" Orientation="Horizontal" >
                <Button Content="1"/>
                <Button Content="2"/>
                <Button Content="3"/>
                <Button  Content="4"/>
            </StackPanel>
        </Grid>
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="{Binding ElementName=SomeLabel, Path=DesiredSize.Height}"/>
                <RowDefinition Height="{Binding ElementName=SomeLabel, Path=DeisredSize.Height}"/>
                <RowDefinition Height="{Binding ElementName=SomeLabel, Path=DeisredSize.Height}"/>
                <RowDefinition Height="{Binding ElementName=SomeLabel, Path=DeisredSize.Height}"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition  />
                <ColumnDefinition  />
                <ColumnDefinition  />
                <ColumnDefinition  />
                <ColumnDefinition  />
                <ColumnDefinition  />
            </Grid.ColumnDefinitions>

            <Label Content="Fred" Grid.Row="0" x:Name="SomeLabel"/>
            <Label Content="Fred" Grid.Row="0" Grid.Column="1"/>
            <Label Content="Fred" Grid.Row="0" Grid.Column="2" />
            <Label Content="Fred" Grid.Row="0" Grid.Column="3"/>
            <Label Content="Fred" Grid.Row="0" Grid.Column="4"/>
            <Label Content="Fred" Grid.Row="1"/>
            <Label Content="Fred" Grid.Row="2"/>
            <Label Content="Fred" Grid.Row="3"/>
            <ListView Name="FredBox" Grid.Row="0" Grid.Column="5" Grid.RowSpan="4"  />
        </Grid>
    </StackPanel>
</Border>

Viv の提案を使用する

4

1 に答える 1