The WPF display file list uses a ListBox to change to the last DataGrid used by the ListView
Story background:
Need to retrieve files from a directory, list them, and provide options and other features.
First edition requirements:
List the files for selection and the code is as follows:
<listbox name="Multiselectfilelst"Itemssource="{Binding FileList}"grid.row="1"grid.column="1"> <listbox.itemtemplate > <datatemplate > <grid horizontalalignment="Stretch"Verticalalignment="Stretch"> <border margin="5,1,5,1"padding="3"Borderbrush="Green"borderthickness="1"cornerradius="2"> <grid horizontalalignment="Stretch"Verticalalignment="Stretch"> <Grid.ColumnDefinitions> < ColumnDefinition width=" -"></ColumnDefinition> <columndefinition width="Auto"></ColumnDefinition> <columndefinition width=" the"></ColumnDefinition> </Grid.ColumnDefinitions> <checkbox content="{Binding FileName}"tooltip="{Binding FileName}"Ischecked="{Binding IsSelected}"/> <button content="View"Width=" the"Horizontalalignment=" Left"grid.column="2"Command="{Binding Datacontext.openfilecommand, Relativesource={relativesource mode=findancestor, Ancestortype=listbox} }"Commandparameter="{Binding Excelfilepath}"/> </Grid> </Border> </Grid> </d Atatemplate> </ListBox.ItemTemplate> </ListBox>
The Merit:
It's good to use border to draw a border.
Second Edition requirements:
You need to add a directory for the file, so to add a column header, which is implemented with the ListView, the changes are small:
<listview name="Multiselectfilelst"Itemssource="{Binding FileList}"grid.row="1"grid.column="1"> <ListView.View> <gridview > <gridviewcolumn header="file name"> <GridViewColumn.CellTemplate> <dat Atemplate> <checkbox content="{Binding FileName}"tooltip="{Binding FileName}"Ischecked="{Binding IsSelected}"/> </DataTemplate> </gridviewcolumn. Celltemplate> </GridViewColumn> <gridviewcolumn Header="file directory"> <GridViewColumn.CellTemplate> <dat Atemplate> <textblock text="{Binding FolderPath}"tooltip="{Binding FolderPath}"Foreground="Black"/> </DataTemplate> </gridviewcolumn. Celltemplate> </GridViewColumn> <gridviewcolumn Header="View Files"> <GridViewColumn.CellTemplate> <dat Atemplate> <button content="View"Width=" the"Horizontalalignment=" Left"Command="{Binding Datacontext.openfilecommand, Relativesource={relativesource mode=findancestor, Ancestortype=listbox}} "Commandparameter="{Binding Excelfilepath}"/> </DataTemplate> </gridviewcolumn. Celltemplate> </GridViewColumn> </GridView> </ListView.View> </ListView>
Finally, the individual feels that the default style is not good, instead use Actiprosoftware's Themeddatagrid:
<datagrid:themeddatagrid name="Multiselectfilelst"Itemssource="{Binding FileList}"grid.row="1"grid.column="1"AutoGenerateColumns="False"Canuseraddrows="False"Canuserresizerows="False"Canuserdeleterows="False"Arerowdetailsfrozen="False"canusersortcolumns="False"canuserreordercolumns="False"headersvisibility="Column"selectionunit="Fullrow"> <datagrid:ThemedDataGrid.Columns> <datagridtemplatecolumn Header="file name"isreadonly="True"Width="Auto"> <DataGridTemplateColumn.CellTemplate> <dat Atemplate> <checkbox content="{Binding FileName}"tooltip="{Binding FileName}"Ischecked="{Binding IsSelected}"margin="0,0,20,0"/> </DataTemplate> </datagridtemplatecolumn. Celltemplate> </datagridtemplatecolumn > <datagridtempla Tecolumn header="file directory"isreadonly="True"Width="Auto"> <DataGridTemplateColumn.CellTemplate> <dat Atemplate> <textblock text="{Binding FolderPath}"tooltip="{Binding FolderPath}"margin="20,0,20,0"/> </DataTemplate> </datagridtemplatecolumn. Celltemplate> </datagridtemplatecolumn > <datagridtempla Tecolumn header="View Files"isreadonly="True"Width=" the"> <DataGridTemplateColumn.CellTemplate> <dat Atemplate> <button content="View"Horizontalalignment=" Left"Width=" the"Command="{Binding Datacontext.openfilecommand, Relativesource={relativesource mode=findancestor, Ancestortype=listbox} }"CommandParameter="{Binding Excelfilepath}"/> </DataTemplate> </datagridtemplatecolumn. Celltemplate> </datagridtemplatecolumn > </datagrid:themedda Tagrid.columns> </datagrid:ThemedDataGrid>
There are questions: the template length setting in the ListBox does not scale with the interface, and subsequent fixes are made.
The WPF display file list uses a ListBox to change to the last DataGrid used by the ListView