C# 单击按钮将图像插入Windows 8应用程序
我正在创建一个Windows8应用程序,想知道做某事的最佳方式。我想做的是让图像显示在我的应用程序一侧的另一个下面。因此,单击按钮时,图像会显示在已存在的图像下。有人知道我将如何使用Listbox的任何示例或建议吗C# 单击按钮将图像插入Windows 8应用程序,c#,windows-8.1,C#,Windows 8.1,我正在创建一个Windows8应用程序,想知道做某事的最佳方式。我想做的是让图像显示在我的应用程序一侧的另一个下面。因此,单击按钮时,图像会显示在已存在的图像下。有人知道我将如何使用Listbox的任何示例或建议吗 <Grid > <ListView ItemsSource="{Binding PhotoList}"> <ListView.ItemTemplate> <DataTemplate>
<Grid >
<ListView ItemsSource="{Binding PhotoList}">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding PhotoName}"></TextBlock>
<Image Source="{Binding Photo}" Width="100" Height="100"></Image>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
public class PhotoItem
{
public string PhotoName { get; set; }
public BitmapImage Photo { get; set; }
public static List<PhotoItem> GetPhotos()
{
return new List<PhotoItem>()
{
new PhotoItem(){PhotoName="Image1",Photo = new BitmapImage(new Uri("/Images/Image1.jpg", UriKind.Relative))},
new PhotoItem(){PhotoName="Image2",Photo = new BitmapImage(new Uri("/Images/Image2.jpg", UriKind.Relative))},
};
}
}
public class PhotoItemViewModel : INotifyPropertyChanged
{
private ObservableCollection<PhotoItem> photoList;
public ObservableCollection<PhotoItem> PhotoList
{
get
{
return photoList;
}
set
{
photoList = value;
NotifyPropertyChanged();
}
}
public void LoadData()
{
PhotoList = new ObservableCollection<PhotoItem>(PhotoItem.GetPhotos());
}
public event PropertyChangedEventHandler PropertyChanged;
public void NotifyPropertyChanged([CallerMemberName] string propertyName = null)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
PhotoItemViewModel viewModel = new PhotoItemViewModel();
public MainPage()
{
InitializeComponent();
this.Loaded += MainPage_Loaded;
}
void MainPage_Loaded(object sender, RoutedEventArgs e)
{
viewModel.LoadData();
DataContext = viewModel;
}