我在ViewMode中有一个网格(BrkGrid)...我根据一些逻辑添加动态复选框(brkChkBox)。 foreach负责将复选框添加到此网格的特定行和列中。但是将复选框添加到BrkGrid时需要花费时间。当我评论Add语句(BrkGrid.Children.Add(brkChkBox))时,代码执行得更快..任何帮助都将受到高度赞赏......
CheckBox brkChkBox = null;
foreach (var s in this.ViewData.PlnDtShiftBrksDateList)
{
brkChkBox = new CheckBox
{
DataContext = s,
Tag = s.BreakID,
Width = 20,
VerticalAlignment = VerticalAlignment.Top,
};
Binding chkBoxBinding = new Binding("IsSelected");
chkBoxBinding.Source = s;
chkBoxBinding.Mode = BindingMode.TwoWay;
brkChkBox.SetBinding(CheckBox.IsCheckedProperty, chkBoxBinding);
brkChkBox.Click += brkChkBox_Click;
Grid.SetColumn(brkChkBox, gridColDic.FirstOrDefault(x => x.Key == s.BreakID).Value);
Grid.SetRow(brkChkBox, gridRowDic.FirstOrDefault(x => x.Key.Date == s.Date.Date).Value);
BrkGrid.Children.Add(brkChkBox);
}