Upgrading to .NET 4.5: An ItemsControl is inconsistent with its items source

WPF 4.5 provides some new functionality to access collections on non-UI Threads. It WPF enables you to access and modify data collections on threads other than the one that created the collection. This enables you to use a background thread to receive data from an external source, such as a database, and display the data … Read more

WPF Datagrid Row Editing “ENDED” event

private void dgrid_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e) { if (this.dgrid.SelectedItem != null) { (sender as DataGrid).RowEditEnding -=dgrid_RowEditEnding; (sender as DataGrid).CommitEdit(); (sender as DataGrid).Items.Refresh(); (sender as DataGrid).RowEditEnding += dgrid_RowEditEnding; } else Return; //then check if the newly added row is duplicated }

How to Freeze First Column of WPF DataGrid [duplicate]

Set the DataGrid’s FrozenColumnCount=”1″. <DataGrid FrozenColumnCount=”1″ Name=”dgQuestionTemplate” HorizontalAlignment=”Left” Grid.Row=”1″ Width=”870″ HorizontalScrollBarVisibility=”Auto” IsReadOnly=”False”> Frozen columns are columns that are always displayed and cannot be scrolled out of visibility. Frozen columns are always the leftmost columns in display order. You cannot drag frozen columns into the group of unfrozen columns or drag unfrozen columns into the group … Read more

WPF DataGrid: how do I stop auto scrolling when a cell is clicked?

Define an EventSetter in the DataGrid.RowStyle to call a handler that prevents the row from being brought into view: XAML <DataGrid> <DataGrid.RowStyle> <Style TargetType=”{x:Type DataGridRow}”> <EventSetter Event=”Control.RequestBringIntoView” Handler=”DataGrid_Documents_RequestBringIntoView” /> </Style> </DataGrid.RowStyle> </DataGrid> Handler private void DataGrid_Documents_RequestBringIntoView(object sender, RequestBringIntoViewEventArgs e) { e.Handled = true; }

Simple way to display row numbers on WPF DataGrid

One way is to add them in the LoadingRow event for the DataGrid <DataGrid Name=”DataGrid” LoadingRow=”DataGrid_LoadingRow” … void DataGrid_LoadingRow(object sender, DataGridRowEventArgs e) { e.Row.Header = (e.Row.GetIndex()).ToString(); } When items are added or removed from the source list then the numbers can get out of sync for a while. For a fix to this, see the … Read more

Improve WPF DataGrid performance

There are a few options you can turn on to help you on your DataGrid object EnableColumnVirtualization = true EnableRowVirtualization = true These two are the main ones I think might help. Next try making your binding async ItemsSource=”{Binding MyStuff, IsAsync=True}” And lastly, I’ve heard that setting a maximum height and width can help even … Read more