我想用类似于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
}
}
答案 0 :(得分:1)
您可以使用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>