[英]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.