0
徘徊如果我可以得到幫助,單擊時組合框列出hdds我希望列表框列出來自相應hdd的位圖圖像縮略圖(每個選定的HDD都將轉換爲我希望使用的字符串作爲獲取縮略圖的地址,我原本有助於讓這個工作與完整的圖像,但因爲這很慢我正在試驗縮略圖,到目前爲止我沒有任何錯誤,但沒有在列表框中顯示,我確定我已綁定位圖縮略圖的地址問題
public MainWindow()
{
InitializeComponent();
DataContext = this;
}
private void Window_Loaded(object sender, RoutedEventArgs e) //Window Loaded Event
{
///Load Avaliable Drives Into ComboBox
string[] drives = Environment.GetLogicalDrives(); //Drive Letters, Into A String Array
foreach (string drive in drives)
{
HDDSelectionBox.Items.Add(drive); //Adds Each Drive Letter As A Combox Box Item
}
string root = (HDDSelectionBox.SelectedItem.ToString()); //Contains Directory Path For Images
string[] supportedExtensions = new[] { ".bmp", ".jpeg", ".jpg", ".png", ".tiff" };
var files = System.IO.Directory.EnumerateFiles(root, "*.*").Where(s => supportedExtensions.Contains(System.IO.Path.GetExtension(s).ToLower()));
List<Photos> images = new List<Photos>();
if (HDDSelectionBox.SelectedItem != null) //If a item has been selected
{
foreach (var file in files)
{
Photos id = new Photos()
{
Path = file,
FileName = System.IO.Path.GetFileName(file),
Extension = System.IO.Path.GetExtension(file)
};
BitmapImage img = new BitmapImage();
img.BeginInit();
img.CacheOption = BitmapCacheOption.OnLoad;
img.UriSource = new Uri(file, UriKind.Absolute);
img.EndInit();
id.Width = img.PixelWidth;
id.Height = img.PixelHeight;
// I couldn't find file size in BitmapImage
FileInfo fi = new FileInfo(file);
id.Size = fi.Length;
images.Add(id);
}
ImageListBox.ItemsSource = images;
}
}
}
public class Photos
{
/// <summary>
/// A name for the image, not the file name.
/// </summary>
public string Name { get; set; }
/// <summary>
/// A description for the image.
/// </summary>
public string Description { get; set; }
/// <summary>
/// Full path such as c:\path\to\image.png
/// </summary>
public string Path { get; set; }
/// <summary>
/// The image file name such as image.png
/// </summary>
public string FileName { get; set; }
/// <summary>
/// The file name extension: bmp, gif, jpg, png, tiff, etc...
/// </summary>
public string Extension { get; set; }
/// <summary>
/// The image height
/// </summary>
public int Height { get; set; }
/// <summary>
/// The image width.
/// </summary>
public int Width { get; set; }
/// <summary>
/// The file size of the image.
/// </summary>
public long Size { get; set; }
}
}
哇那有點採取,但謝謝你,我會嘗試 –
其實,這樣的XAML可以正確地綁定到你的代碼的大多數代碼都涉及到財產的通知..把所有這些東西都拿走,你會發現它其實很簡單。在真實世界的應用程序(比如數據庫應用程序)中,通常使用CastleProxy設置體系結構或創建包裝類,以便自動生成所有代碼。對於像這樣的基本東西,雖然很容易就可以根據需要隨時做,一旦得到了ObservableObject類。 –
我只是新的建模,我慢慢掌握了綁定,資源和數據模板等想法,但havnt花了很多時間在模型和通知等,所以希望它不是很難讓我的頭周圍的模型的東西 –