WPF 控件【L】ListView(三) ListView+GridView+GridViewColumn+DisplayMemberBinding多列绑定数据的用法

 一、ListView 基础

我在叙述一下ListView 基础的东西,内容不是很齐备。

1、设置列表头

ColumnHeaderContainerStyle用来设置整个列表头的字体及其背景颜色等等。

2、设置列表内容

ItemContainerStyle用来设置列表内容的字体及其背景颜色等等。

此外,Padding可以设置边距。

列表内容居中:

 

ListView 部分代码

 <ListView x:Name="EnableSelectView" Canvas.Top="95" BorderThickness="1" Height="378" Width="462" ItemContainerStyle="{StaticResource ListViewItemContainerStyleForStudyPage}">
                        <ListView.View>
                            <GridView ColumnHeaderContainerStyle="{StaticResource DefaultGridViewColumnHeaderForStudyPage}">
                                <GridViewColumn x:Name="headerProtocolNum" Header="协议编号" Width="230" >
                                    <GridViewColumn.CellTemplate>
                                        <DataTemplate>
                                            <TextBlock Text="{Binding ProtocolNum}" Width="230" Padding="60,0,0,0"/>
                                        </DataTemplate>
                                    </GridViewColumn.CellTemplate>
                                </GridViewColumn>

                                <GridViewColumn x:Name="headerProtocolName" Header="协议名称" Width="230" >
                                    <GridViewColumn.CellTemplate>
                                        <DataTemplate>
                                            <TextBlock Text="{Binding ProtocolName}" Width="230" Padding="60,0,0,0"/>
                                        </DataTemplate>
                                    </GridViewColumn.CellTemplate>
                                </GridViewColumn>
                            </GridView>
                        </ListView.View>
                    </ListView>

参考:

入门参考https://blog.csdn.net/lovefenglinshi/article/details/24887783

双向绑定参考(可以实现动态删除、添加、读取列表的等。不用每次都重新赋值数组,然后读取显示) https://www.cnblogs.com/santian/p/4366832.html

 

二、ListView  + ItemsSource+ Binding

     <ListView x:Name="lvPatientList" Height="536" Width="1904" Style="{StaticResource ListViewStyle_HistoryPage1}" ItemContainerStyle="{StaticResource ListViewItemContainerStyle}" ItemsSource="{Binding PatientInfoList}" >
                <ListView.View>
                    <GridView ColumnHeaderContainerStyle="{StaticResource DefaultGridViewColumnHeader57x1527}" x:Name="lvGridView">
                        <GridViewColumn Header="{DynamicResource History.ListView_Checking.PatientInfo.Content}" Width="135" DisplayMemberBinding="{Binding Path=PatientInfo}"/>
                        <GridViewColumn Header="{DynamicResource History.ListView_Checking.CheckingNum.Content}" Width="150" DisplayMemberBinding="{Binding Path=StudyID}"/>
                        <GridViewColumn Header="{DynamicResource History.ListView_Checking.Name.Content}" Width="78" DisplayMemberBinding="{Binding Path=PatientName}"/>
                        <GridViewColumn Header="{DynamicResource History.ListView_Checking.Sex.Content}" Width="78" DisplayMemberBinding="{Binding Path=PatientSex}"/>

                        <GridViewColumn Header="{DynamicResource History.ListView_Checking.Age.Content}" Width="78" DisplayMemberBinding="{Binding Path=PatientAge}"/>
                        <GridViewColumn Header="{DynamicResource History.ListView_Checking.Birth.Content}" Width="104" DisplayMemberBinding="{Binding Path=PatientBrith}"/>
                        <GridViewColumn Header="{DynamicResource History.ListView_Checking.Height.Content}" Width="118" DisplayMemberBinding="{Binding Path=PatientHeight}"/>
                        <GridViewColumn Header="{DynamicResource History.ListView_Checking.Weight.Content}" Width="106" DisplayMemberBinding="{Binding Path=PatientWeight}"/>

                        <GridViewColumn Header="{DynamicResource History.ListView_Checking.RecordSource.Content}" Width="112" DisplayMemberBinding="{Binding Path=RecordSource}"/>
                        <GridViewColumn Header="{DynamicResource History.ListView_Checking.CheckingTime.Content}" Width="103" DisplayMemberBinding="{Binding Path=StudyTime}"/>
                        <GridViewColumn Header="{DynamicResource History.ListView_Checking.EquipmentType.Content}" Width="103" DisplayMemberBinding="{Binding Path=EquipmentType}"/>
                        <GridViewColumn Header="{DynamicResource History.ListView_Checking.CheckParts.Content}" Width="226" DisplayMemberBinding="{Binding Path=StudyPart}"/>

                        <GridViewColumn Header="{DynamicResource History.ListView_Checking.SequencesNum.Content}" Width="112" DisplayMemberBinding="{Binding Path=SequenceAmount}"/>
                        <GridViewColumn Header="{DynamicResource History.ListView_Checking.CheckStutas.Content}" Width="112" DisplayMemberBinding="{Binding Path=StudyStutas}"/>
                        <GridViewColumn Header="{DynamicResource History.ListView_Checking.SuspendState.Content}" Width="112" DisplayMemberBinding="{Binding Path=SuspendState}"/>
                        <GridViewColumn Header="{DynamicResource History.ListView_Checking.FilmPrint.Content}" Width="112" DisplayMemberBinding="{Binding Path=FilmPrint}"/>

                        <!--<GridViewColumn Header="{DynamicResource History.ListView_Checking.PatientInfo.Content}" Width="135"/>
                        <GridViewColumn Header="{DynamicResource History.ListView_Checking.CheckingNum.Content}" Width="150" />
                        <GridViewColumn Header="{DynamicResource History.ListView_Checking.Name.Content}" Width="78" />
                        <GridViewColumn Header="{DynamicResource History.ListView_Checking.Sex.Content}" Width="78" />

                        <GridViewColumn Header="{DynamicResource History.ListView_Checking.Age.Content}" Width="78" />
                        <GridViewColumn Header="{DynamicResource History.ListView_Checking.Birth.Content}" Width="104" DisplayMemberBinding="{Binding Path=PatientBrith}"/>
                        <GridViewColumn Header="{DynamicResource History.ListView_Checking.Height.Content}" Width="118" DisplayMemberBinding="{Binding Path=PatientHeight}"/>
                        <GridViewColumn Header="{DynamicResource History.ListView_Checking.Weight.Content}" Width="106" DisplayMemberBinding="{Binding Path=PatientWeight}"/>

                        <GridViewColumn Header="{DynamicResource History.ListView_Checking.RecordSource.Content}" Width="112" DisplayMemberBinding="{Binding Path=RecordSource}"/>
                        <GridViewColumn Header="{DynamicResource History.ListView_Checking.CheckingTime.Content}" Width="103" DisplayMemberBinding="{Binding Path=StudyTime}"/>
                        <GridViewColumn Header="{DynamicResource History.ListView_Checking.EquipmentType.Content}" Width="103" DisplayMemberBinding="{Binding Path=EquipmentType}"/>
                        <GridViewColumn Header="{DynamicResource History.ListView_Checking.CheckParts.Content}" Width="226" DisplayMemberBinding="{Binding Path=StudyPart}"/>

                        <GridViewColumn Header="{DynamicResource History.ListView_Checking.SequencesNum.Content}" Width="112" DisplayMemberBinding="{Binding Path=SequenceAmount}"/>
                        <GridViewColumn Header="{DynamicResource History.ListView_Checking.CheckStutas.Content}" Width="112" DisplayMemberBinding="{Binding Path=StudyStutas}"/>
                        <GridViewColumn Header="{DynamicResource History.ListView_Checking.SuspendState.Content}" Width="112" DisplayMemberBinding="{Binding Path=SuspendState}"/>
                        <GridViewColumn Header="{DynamicResource History.ListView_Checking.FilmPrint.Content}" Width="112" DisplayMemberBinding="{Binding Path=FilmPrint}"/>-->

                    </GridView>
                </ListView.View>
            </ListView>

 

©️2020 CSDN 皮肤主题: 技术工厂 设计师:CSDN官方博客 返回首页