我想在Windows商店应用程序上为媒体创建示例数据,我创建了一个如下所示的DigitalMedia类
public class DigitalMedia
{
public string Title { get; set; }
public string Author { get; set; }
public string Subject { get; set; }
public string Format { get; set; }
public double Duration { get; set; }
public string Description { get; set; }
public ImageSource TitleImage { get; set; }
public ImageSource Thumbnail { get; set; }
public Uri PurchaseLink { get; set; }
}
我还创建了另一个名为GroupedMedia的类来表示一组DigitalMedia类。这段代码在
下面public class GroupedMedia : INotifyPropertyChanged
{
public string GroupTitle { get; set; }
public string Description { get; set; }
public ImageSource GroupImage { get; set; }
private ObservableCollection<DigitalMedia> _mediaList = null;
public ObservableCollection<DigitalMedia> MediaList
{
get
{
if (_mediaList == null)
_mediaList = new ObservableCollection<DigitalMedia>();
return _mediaList;
}
set
{
_mediaList = value;
RaisePropertyChanged("MediaList");
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void RaisePropertyChanged(string property)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(property));
}
答案 0 :(得分:0)
1-如果这仅用于测试目的,您只需在MainWindow.xaml.cs的InitializeComponent()下面添加对象的初始化。
3-将DataGrid放在主窗口中,如下所示:
public MainWindow()
{
InitializeComponent();
//Initialize your data here
GroupedMedia gm = new GroupedMedia();
//Initialize your data here
this.dgTest.ItemsSource = gm.MediaList;
}
然后将其ItemsSource设置为您的数据。
(?<=[?&]id=)[^&]+
答案 1 :(得分:0)
尝试这样的事情
static void Main(string[] args)
{
GroupedMedia groupedMedia = new GroupedMedia();
List<DigitalMedia> digitalMedias = new List<DigitalMedia>();
for(int i = 0; i < 5; i++)
{
DigitalMedia digitalMedia = new DigitalMedia();
digitalMedias.Add(digitalMedia);
digitalMedia.Author = "John";
}
groupedMedia.MediaList = digitalMedias;
}