【问题标题】:Updating listview height to fill new form content (c#)更新列表视图高度以填充新表单内容(c#)
【发布时间】:2013-05-08 03:42:49
【问题描述】:

我有一个带有边框的表单,其中包含一个列表视图,在我的 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>

【问题讨论】:

    标签: c# xml listview height


    【解决方案1】:

    Xaml 中,您通过将&lt;RowDefinition Height="70"/&gt; 和宽度设置为90 将ListView 的高度设置为70,ListView 不会变得更大,您需要设置&lt;RowDefinition Height="70*"/&gt; 允许它增加高度并删除 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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-05-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-19
      • 1970-01-01
      • 2012-01-01
      • 1970-01-01
      相关资源
      最近更新 更多