我正在写一个应用程序,将显示几个jpeg的缩略图与他们的文件名下。我想按文件名对它们进行排序。这些jpeg是从zip文件中出来的,我无法按排序顺序接收它们。我使用的列表框定义如下:
<ListBox Name="listPanel1" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Auto" SelectionMode="Multiple" >
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Name="wrapPanel1" IsItemsHost="True" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<TextBox Height="152" Name="tb_Messages" Width="244" />
</ListBox>然后在代码中,我为listPanel中的每个缩略图添加了一个单独的网格控件。网格的第一行是图像,第二行是文件名。
Grid grid = new Grid();
ColumnDefinition col0 = new ColumnDefinition();
RowDefinition row0 = new RowDefinition();
RowDefinition row1 = new RowDefinition();
col0.Width = new GridLength(140);
row0.Height = new GridLength(140);
grid.ColumnDefinitions.Add(col0);
grid.RowDefinitions.Add(row0);
grid.RowDefinitions.Add(row1);
grid.Children.Add(thumbnailImage);
grid.Children.Add(lb);
Grid.SetRow(thumbnailImage, 0);
Grid.SetColumn(thumbnailImage, 0);
Grid.SetRow(fileName, 1);
Grid.SetColumn(fileName, 0);
listPanel1.Items.Add(grid);这种方法的一个优点是,当我选择一个图像时,图像和文件名都会高亮显示。
如何根据文件名对列表框进行排序?
这是我的第一个WPF应用,所以我完全有可能以一种完全错误的方式来处理这个问题。
https://stackoverflow.com/questions/12435634
复制相似问题