WPF DataGrid : CanContentScroll property causing odd behavior

You are encountering the differences between physical scrolling and logical scrolling. As you have discovered, each has its tradeoffs. Physical scrolling Physical scrolling (CanContentScroll=false) just goes by pixels, so: The viewport always represents exactly the same portion of your scroll extent, giving you a smooth scrolling experience, and but The entire contents of the DataGrid … Read more

What is the proper way to handle multiple datagrids in a tab control so that cells leave edit mode when the tabs are changed?

I implemented a behavior for the DataGrid based on code I found in this thread. Usage:<DataGrid local:DataGridCommitEditBehavior.CommitOnLostFocus=”True” /> Code: using System.Collections.Generic; using System.Reflection; using System.Windows; using System.Windows.Controls; using System.Windows.Controls.Primitives; using System.Windows.Input; using System.Windows.Media; /// <summary> /// Provides an ugly hack to prevent a bug in the data grid. /// https://connect.microsoft.com/VisualStudio/feedback/details/532494/wpf-datagrid-and-tabcontrol-deferrefresh-exception /// </summary> public class DataGridCommitEditBehavior … Read more

Filter a DataGrid on a Text box

You can filter the Items in the DataGrid by binding it to an ICollectionView that supports filtering. Details here for .NET 4. The process is the same for .NET 4.5, but it seems the documentation has been lost. There’s a small mention to it here under the “Grouping, Sorting, and Filtering” heading. edit: at the … Read more

WPF datagrid selected row clicked event ?

you can add the event handler in the ItemContainerStyle (which is the style applied to a row) : <DataGrid … > <DataGrid.ItemContainerStyle> <Style TargetType=”DataGridRow”> <EventSetter Event=”MouseDoubleClick” Handler=”Row_DoubleClick”/> </Style> </DataGrid.ItemContainerStyle> … </DataGrid> Then, in the handler, you can check if the row is selected private void Row_DoubleClick(object sender, MouseButtonEventArgs e) { // execute some code }

How do I bind a List to a WPF DataGrid?

if you do not expect that your list will be recreated then you can use the same approach as you’ve used for Asp.Net (instead of DataSource this property in WPF is usually named ItemsSource): this.dataGrid1.ItemsSource = list; But if you would like to replace your list with new collection instance then you should consider using … Read more