我创建了一个包含一些按钮和一个DataGrid的 View 。当应用程序解析excel文件时,DataGrid将显示项目。我添加了一个取消解析线程的按钮。我能够清除DataGrid的唯一问题是,如果对任何列进行了排序,则该排序在取消之前一直存在。
这是我的Datagrid的一个示例:
<DataGrid ItemsSource="{Binding Parts}"
Visibility="{Binding DatagridIsVisible, Converter={StaticResource BooleanToVisibilityInverseParameterConverter}}"
AutoGenerateColumns="False"
Margin="0,0,0,44"
FontSize="20"
AlternationCount="2"
AlternatingRowBackground="WhiteSmoke"
CanUserAddRows="False">
<DataGrid.Columns >
<DataGridTextColumn Header="Raw Data"
Binding="{Binding RawData}">
<DataGridTextColumn.CellStyle>
<Style>
<Setter Property="Border.BorderBrush" Value="Black"/>
<Setter Property="Border.BorderThickness" Value="0 0 1 0"/>
</Style>
</DataGridTextColumn.CellStyle>
</DataGridTextColumn>
<DataGridTextColumn Header="Manufacturer" Binding="{Binding Manu}">
<DataGridTextColumn.CellStyle>
<Style>
<Setter Property="Border.BorderBrush" Value="Black"/>
<Setter Property="Border.BorderThickness" Value="0 0 1 0"/>
</Style>
</DataGridTextColumn.CellStyle>
</DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
我通过互联网进行了梳理,并找到了有关如何使用背后的代码方法执行此操作的示例,但我确实在尝试使用MVVM。
这有可能吗?
最佳答案
我认为您应该为ItemsSource 使用集合 View 而不是Observable集合,因为如果使用Observable集合,则只有一个Collection View,因此所有更改都将保留。但是,如果使用“收藏夹 View ”,则可以更改收藏夹 View 并删除排序。
你可以see more here
希望对您有所帮助
关于c# - 重置DataGrid排序回到其初始状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36179340/