string[] list = Directory.GetFiles(@"Resources/", "*.jpg");
lvDataBinding.Items.Add(list[0]);
因此,資源文件夾包含幾個圖像,我想添加到一個數組,所以我可以用一個更簡單的方式使用它們。C# - 如何將文件夾中的圖像添加到數組並將它們顯示在列表視圖中?
我需要將它們顯示在一個窗口中(每次選擇不同的listviewitem時)。
我想知道我是否也可以將它們存儲在ListViewItem名稱和說明旁邊的類中。所以我可以這樣做:
Article article1= new Article();
article1.Name = "Article name";
article1.Description = "Long article description etc etc";
article1.Image= images[0];
lvDataBinding.Items.Add(artikel1);
然後類會是這樣的東西我猜?
public class Article
{
public string Name{ get; set; }
public string Description{ get; set; }
public Image? Image { get; set; }
public override string ToString()
{
return Naziv;
}
}
P.S .:我尊重所有關於如何以另一種更好的方式做到這一點的建議。我確定有更好的方法,但我正在做一項大學作業,而且時間有限,我的老師也建議將對象「轉移」到新窗口中。 在此先感謝!
用'ICollection'屬性創建一個'ViewModel'和使用該財產爲'ItemsSource'你'ListBox'。 – AnjumSKhan
你能詳細談談細節嗎?我不太明白。另外,我有ListView而不是ListBox。 – Yanketz
答案是肯定的,你可以這樣做。但是,你必須對你的問題更具體。我不認爲一個簡單的「是」答案可以幫助你解決問題。 –