Reputation: 3264
I have a DataGrid
with ids which is to be shown in ascending order from top to bottom . However the last ids(hightest number) has to be shown initially, but still in the bottom part of the DataGrid
. This means you have to scroll to the top to reveal the old ids.
Is it possible to do this with virtualization still intact?
We are using sfdatagrid(syncfusion). However if any other grid(including wpf native grid) has this covered I can look into that
Upvotes: 0
Views: 136
Reputation: 169350
Is it possible to do this with virtualization still intact?
Yes. At least using the built-in DataGrid
control. It's just a matter of scrolling to the bottom before any containers have been created. Please refer to the following sample code:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
numberGrid.ItemsSource = Enumerable.Range(1, 100);
numberGrid.ScrollIntoView(numberGrid.Items[numberGrid.Items.Count - 1]);
}
int n = 0;
private void DataGridRow_Loaded(object sender, RoutedEventArgs e)
{
txt.Text = (n++).ToString();
}
}
XAML:
<DataGrid x:Name="dg" Height="200">
<DataGrid.ItemContainerStyle>
<Style TargetType="DataGridRow">
<EventSetter Event="Loaded" Handler="DataGridRow_Loaded" />
</Style>
</DataGrid.ItemContainerStyle>
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding}" />
</DataGrid.Columns>
</DataGrid>
<TextBlock x:Name="txt" />
Only 11 containers are loaded in the visual tree:
Upvotes: 4