[英]WPF Datagrid rows do not get cleared - C#
我有一个datagrid
; 通过observable collection
填充Printreport
; PopulatePatternData
运行正常,并且在运行程序时显示所有行。 当程序重新运行时,我想用新的数据行更新数据网格,但是将新数据与以前的结果(行)一起添加
XAML:
<DataGrid x:Name="PrintReport" ItemsSource="{Binding PopulatePatternData}" AutoGenerateColumns="False" FontFamily="Tahoma" FontSize="12" CanUserSortColumns="False"
HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" AlternatingRowBackground="Gainsboro" AlternationCount="1"
SelectionMode="Extended" SelectionUnit="Cell" >
我用来运行程序的按钮(RunAnalysis)具有event handler
。 当单击observable collection
然后创建数据网格时,我将其清除。 我试图如下所示clear
“ datagrid”行,但无济于事。
private void RunAnalysis(object sender, RoutedEventArgs e)
{
WFPlanningCompliancePluginModel model = DataContext as WFPlanningCompliancePluginModel;
model.PopulatePatternData.Clear();
PrintReport.Items.Clear(); // This does not work
model.Run();
}
collection
将被清除,但不会清除datagrid
! 我在做什么错? 如果我使用该程序,则在第一次运行时会失败
PrintReport.Items.Clear(); as it does not find any items.
清除项目后,重新DataGrid
:
private void RunAnalysis(object sender, RoutedEventArgs e)
{
WFPlanningCompliancePluginModel model = DataContext as WFPlanningCompliancePluginModel;
model.PopulatePatternData.Clear();
// PrintReport.Items.Clear(); // This you can skip if the binding works.
PrintReport.DataBind(); // This should be enough if the binding works correctly!
model.Run();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.