0

我有一个带有边框的表单,其中包含一个列表视图,在我的 c# 代码中,边框的高度根据一个值而变化。现在边框高度变化没有问题但是我如何更新列表视图以与边框具有相同的高度?这是我的xml:

 <DataTemplate x:Key="PackageTemplate">
        <Border x:Name="PackageBorder" BorderBrush="Black" BorderThickness="2" Margin="10" Padding="0" Width="100" >
            <Border.Style>
                <Style>
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding Path=Status}" Value="1">
                            <Setter Property="Border.Background" Value="#FF999696"/>
                        </DataTrigger>
                        <DataTrigger Binding="{Binding Path=Status}" Value="0">
                            <Setter Property="Border.Background" Value="#FFE4E4E4"/>
                        </DataTrigger>
                        <DataTrigger Binding="{Binding Path=Layout}" Value="0">
                            <Setter Property="Border.Height" Value="100"/>
                        </DataTrigger>
                        <DataTrigger Binding="{Binding Path=Layout}" Value="1">
                            <Setter Property="Border.Height" Value="200"/>
                        </DataTrigger>
                    </Style.Triggers>                           
                </Style>
            </Border.Style>
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="70"/>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>

                <ListView  Grid.Row="0" Grid.Column="0" Background="{x:Null}" x:Name="List" ItemsSource="{Binding Path=Collection}" ItemTemplate="{DynamicResource ChipTemplate}" 
                          ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Disabled" BorderThickness="0" BorderBrush="{x:Null}" Foreground="Black" VerticalAlignment="Top" Width="90" >
                    <ListView.ItemsPanel>
                        <ItemsPanelTemplate>
                            <WrapPanel Orientation="Horizontal" VerticalAlignment="Center" />
                        </ItemsPanelTemplate>
                    </ListView.ItemsPanel>
                </ListView>

                <Label Grid.Row="1" Grid.Column="0" Content="{Binding Path=Location}" FontSize="15" FontFamily="Arial" Foreground="Black" Background="{x:Null}" VerticalAlignment="Bottom" HorizontalAlignment="Left"></Label>                  
            </Grid>
        </Border>            
    </DataTemplate>
4

1 回答 1

2

Xaml您通过设置将 ListView 高度设置为 70<RowDefinition Height="70"/>并将宽度设置为 90 时,ListView将不会变得更大,您需要设置<RowDefinition Height="70*"/> 允许它增加高度并删除 Width="90",或者可能使用DockPanel.

    <DockPanel>
        <Label DockPanel.Dock="Bottom" Content="{Binding Path=Location}" FontSize="15" FontFamily="Arial" Foreground="Black"  />
        <ListView x:Name="List" ItemsSource="{Binding Path=Collection}" ItemTemplate="{DynamicResource ChipTemplate}" 
                      ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Disabled" BorderThickness="0" BorderBrush="{x:Null}" Foreground="Black" >
            <ListView.ItemsPanel>
                <ItemsPanelTemplate>
                    <WrapPanel Orientation="Horizontal" VerticalAlignment="Center" />
                </ItemsPanelTemplate>
            </ListView.ItemsPanel>
        </ListView>
    </DockPanel>
于 2013-05-14T01:10:12.487 回答