标签:detail mss 模拟 schedule EDA 包含 params try 对象
原文:WPF 动态生成对象属性 (dynamic)
项目中列行的数据 都需要动态生成 所以考虑到对象绑定 可需要一个动态生成属性的意思
缺点 加载速度会慢 很明显的慢
解决办法 尽量减轻动态属性的量~
参考文章
https://www.cnblogs.com/maomiyouai/p/3594132.html
https://www.cnblogs.com/dingli/archive/2012/06/14/2548687.html(这个没看明白 但是冥冥中让我觉得 收藏一下以后可能会用)
代码
属性类 想研究明白的 看参考文章
-
public class NurseScheduleStatisticsModel : DynamicObject
-
-
-
-
Dictionarystring, object> Properties = new Dictionarystring, object>();
-
-
public override bool TrySetMember(SetMemberBinder binder, object value)
-
-
if (!Properties.Keys.Contains(binder.Name))
-
-
-
Properties.Add(binder.Name, value.ToString());
-
-
-
-
public override bool TryGetMember(GetMemberBinder binder, out object result)
-
-
return Properties.TryGetValue(binder.Name, out result);
-
-
生成临时数据
-
private ObservableCollectionGetNameDataLlist()
-
-
-
dynamic model = new NurseScheduleStatisticsModel();
-
-
-
-
-
-
-
-
-
-
dynamic model2 = new NurseScheduleStatisticsModel();
-
-
-
-
-
-
-
-
-
-
dynamic model3 = new NurseScheduleStatisticsModel();
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
动态增加列和绑定datagrid
dl.Binding = new Binding("Num" + (i + 1) );
这里的bing 绑定的就是对象里的Num1~开始的对象
-
for (int i = 0; i 10; i++)
-
-
DataGridTextColumn dl = new DataGridTextColumn();
-
-
-
dl.Binding = new Binding("Num" + (i + 1) );
-
dataGrid.Columns.Add(dl);
-
-
dataGrid.ItemsSource = GetNameDataLlist();
我在项目里 使用一个自定义对象 来包含 dynamic 动态对象 减少不必要的开销
对象
-
public class NameList : INotifyPropertyChanged
-
-
public event PropertyChangedEventHandler PropertyChanged;
-
-
public NameList(string name, string jOb, string class_, int num, NurseScheduleStatisticsModel model) { Name = name; Class_ = class_; JOb = jOb; Num = num; Ml = model; }
-
-
-
-
-
-
-
-
-
-
-
if (PropertyChanged != null)
-
-
PropertyChanged(this, new PropertyChangedEventArgs("Name"));
-
-
-
-
-
-
-
-
-
-
-
-
-
if (PropertyChanged != null)
-
-
PropertyChanged(this, new PropertyChangedEventArgs("Num"));
-
-
-
-
-
-
-
-
-
-
-
-
if (PropertyChanged != null)
-
-
PropertyChanged(this, new PropertyChangedEventArgs("Class_"));
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
if (PropertyChanged != null)
-
-
PropertyChanged(this, new PropertyChangedEventArgs("JOb"));
-
-
-
-
-
private NurseScheduleStatisticsModel ml;
-
-
public NurseScheduleStatisticsModel Ml
-
-
-
-
if (PropertyChanged != null)
-
-
PropertyChanged(this, new PropertyChangedEventArgs("Ml"));
-
-
-
-
-
-
-
模拟数据
-
private ObservableCollectionGetNameDataLlist2()
-
-
-
dynamic model = new NurseScheduleStatisticsModel();
-
-
-
-
-
-
-
dynamic model2 = new NurseScheduleStatisticsModel();
-
-
-
-
-
-
-
dynamic model3 = new NurseScheduleStatisticsModel();
-
-
-
-
-
-
-
-
-
-
-
-
listName.Add(new NameList("市川 賞子", "リーダー", "B", 1, model));
-
listName.Add(new NameList("石田", "リーダー", "C", 2, model2));
-
listName.Add(new NameList("安达 鮎美", "リーダー", "C", 3, model3));
-
-
-
-
绑定动态列
需要在套一层Ml对象来引用
-
for (int i = 0; i
-
-
DataGridTextColumn dl = new DataGridTextColumn();
-
-
-
dl.Binding = new Binding("Ml.Num" + (i + 1) );
-
dataGrid.Columns.Add(dl);
-
就是慢 的有这点数据量就要4秒~6秒 loading加载提示肯定是要有了
希望有人有更好 更成熟的方法
WPF 动态生成对象属性 (dynamic)
标签:detail mss 模拟 schedule EDA 包含 params try 对象
原文地址:https://www.cnblogs.com/lonelyxmas/p/12075403.html