WPF:如何冻结列表视图下的gridview中的多个列

本文关键字:gridview 视图 列表 何冻结 冻结 WPF | 更新日期: 2023-09-27 18:14:27

我在WPF中有一个列表视图,我想冻结其中的多个列(last four columns)。

下面是我的代码:
 <ListView Name="lvShowSearching" ItemsSource="{Binding Path=.}" Height="248" RenderTransformOrigin="2.25,4" Margin="1129,159,26,93" Grid.RowSpan="2" VerticalAlignment="Center" BorderThickness="2" BorderBrush="#FF90A1CD" Background="White" >
            <ListView.View>
                <GridView>
                    <GridViewColumn Width="0" DisplayMemberBinding="{Binding KeywordID}">
                        <ItemsPanelTemplate>
                            <StackPanel Visibility="Hidden"></StackPanel>
                        </ItemsPanelTemplate>
                    </GridViewColumn>
                    <GridViewColumn Header="First Name" Width="100" DisplayMemberBinding="{Binding FirstName}">
                    </GridViewColumn>
                    <GridViewColumn Header="Last Name" Width="100" DisplayMemberBinding="{Binding LastName}" />
                    <GridViewColumn Header="All Words" Width="100" DisplayMemberBinding="{Binding WithAllOfTheWords}" />
                    <GridViewColumn Header="Exact Phrase" Width="100" DisplayMemberBinding="{Binding WithTheExactPhrase}" />
                    <GridViewColumn Header="At Least One Word" Width="120" DisplayMemberBinding="{Binding WithAtLeastOneOfTheseWords}" />
                    <GridViewColumn Header="Without Word" Width="100" DisplayMemberBinding="{Binding WithoutTheWord}" />
                    <GridViewColumn Header="Exact Date" Width="100" DisplayMemberBinding="{Binding Path=ExactDate, StringFormat='MM/dd/yyyy'}" />
                    <GridViewColumn Header="Start Date" Width="100" DisplayMemberBinding="{Binding Path=StartDate, StringFormat='MM/dd/yyyy'}" />
                    <GridViewColumn Header="End Date" Width="100" DisplayMemberBinding="{Binding Path=EndDate, StringFormat='MM/dd/yyyy'}" />
                    <GridViewColumn Header="Start Year" Width="100" DisplayMemberBinding="{Binding StartYears}" />
                    <GridViewColumn Header="End Year" Width="100" DisplayMemberBinding="{Binding EndYear}" />
                    <GridViewColumn Header="Country" Width="100" DisplayMemberBinding="{Binding CountryName}"/>
                    <GridViewColumn Header="State" Width="100" DisplayMemberBinding="{Binding StateName}" />
                    <GridViewColumn Header="City" Width="100" DisplayMemberBinding="{Binding CityName}" />
                    <GridViewColumn Header="Publication" Width="100" DisplayMemberBinding="{Binding PublicationName}" />
                    <GridViewColumn Header="Total Records" Width="100" DisplayMemberBinding="{Binding TotalRecords}" />
                    <GridViewColumn Header="Records Imported" Width="100" DisplayMemberBinding="{Binding TotalRecordsImported}" />
                    <GridViewColumn Header="Status" Width="100" DisplayMemberBinding="{Binding Status}" />
                    <GridViewColumn Header="Records To Import" Width="100">
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBox Width="70" Name="txtRecordsToImport" Text="{Binding RecordsToImport}"></TextBox>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn Header="Import" Width="70">
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <Button Click="Import_Click">Import</Button>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                </GridView>
            </ListView.View>
        </ListView>

WPF:如何冻结列表视图下的gridview中的多个列

有两种不同的方法可以设置GridViewColumn的可见性。

  1. 带有附加属性
  2. 扩展GridViewColumn

Seting Visibility on a GridViewColum of a ListView in WPF