我想要创建一个界面类似于Windows资源管理器的程序,即显示缩略图和名称、大小等,并且徘徊于要使用的控件。
我想要做的是:
我现在拥有的是这个(稍后将转到一个单独的函数)。
thumb[] thumbs;
public MainWindow() {
InitializeComponent();
int i;
string[] files=Directory.GetFileSystemEntries(@"C:\images","*.jpg",SearchOption.AllDirectories);
System.Drawing.Size mySize=new System.Drawing.Size(128,128);
thumbs=new thumb[files.Length];
for(i=0; i<files.Length ;i++){
thumbs[i]=new thumb(files[i],mySize);
}
//MessageBox.Show("Loaded "+i.ToString()+" images");
}这一点(稍后我可能会切换到使用Image.GetThumbnailImage()作为调整大小的基础):
class thumb {
public Bitmap bmp;
public Size originalSize;
public string path;
public thumb(string path, Size targetSize) {
Bitmap tempBmp;
this.path=path;
tempBmp=new Bitmap(path);
originalSize=tempBmp.Size;
bmp=new Bitmap(tempBmp,targetSize);
tempBmp.Dispose(); //get our memory back
}
}发布于 2014-08-26 09:24:15
您可以使用ListBox作为包含缩略图、名称等控件的容器。您可以为ListBoxItem创建DataTemplate或创建新的UserControl,并将其用作ListBox的内容。
使用WrapPanel可以使它非常响应应用程序窗口的大小。
这里有一个示例,您需要根据您的需要进行更改,但这是一个很好的起点。
<ListBox x:Name="ListOfImages" ItemsSource="{Binding Images}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Width="120" Margin="10" HorizontalAlignment="Left">
<Image Source={Binding ImagePath}" />
<TextBlock Text={Binding Name}" />
</StackPanel>
</DataTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel />
</ItemsPanelTemplate>
</ListBox>https://stackoverflow.com/questions/25501855
复制相似问题