在运行时向样本数据添加新行 [英] Add a new row to sample data at runtime

查看:81
本文介绍了在运行时向样本数据添加新行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有样本数据的原型。我的问题是,是否可以在运行时向样本数据添加新行?

I have a prototype functioning with sample data. My question is, is it possible to add a new row to the sample data at runtime?

提前致谢,

Josh

推荐答案

是的,您只需要获取数据绑定所使用的样本数据实例。

Yes, you just need to get ahold of the instance of sample data being used by databinding.

 

默认情况下,示例数据将datacontext设置为在app.xaml(如果您选择项目范围)或控件的资源(如果您选择此文档)中创建的对象。以下示例适用于项目范围:

By default, sample data sets the datacontext to an object created either in app.xaml (if you picked project scope) or in your control's resources (if you picked this document). The example below is for the project scope:

 


private void AddRow(object sender, System.Windows.RoutedEventArgs e)
		{
			var sd = Application.Current.Resources["SampleDataSource"] as Expression.Blend.SampleData.SampleDataSource.SampleDataSource;
			sd.Collection.Add(new Item() { Property1 = "New Item", Property2 = true });
		}


这篇关于在运行时向样本数据添加新行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆