WPF – DataGrid Column with Width=”*”, but MinWidth to Fit Contents

I know its a bit late, but I found your question and programmed a pure-XAML solution. <ColumnDefinition Width=”42*” MinWidth=”{Binding Path=ActualWidth, ElementName=projectInfoHeader }”/> Where the ElementName points to the control taking up most of the space. Of course thats only possible to do with elements, that do have a limited width. If you do it for … Read more

Filling a Datagrid with dynamic Columns

There are at least three ways of doing this: Modify the DataGrid’s columns manually from code-behind Use a DataTable as the ItemsSource * Use a CustomTypeDescriptor *recommended for simplicity 1st approach: use code-behind to generate the DataGrid’s columns at runtime. This is simple to implement, but maybe feels a bit hackish, especially if you’re using … Read more

WPF DataGrid: CommandBinding to a double click instead of using Events

No need for attached behaviors or custom DataGrid subclasses here. In your DataGrid, bind ItemsSource to an ICollectionView. The trick here is to set IsSynchronizedWithCurrentItem=”True” which means the selected row will be the current item. The second part of the trick is to bind CommandParameter to the current item with the forward slash syntax. When … Read more

Align DataGrid Column Header to Center

Check this <DataGridTextColumn Header=”Nombre” Binding=”{Binding Nombre}”> <DataGridTextColumn.HeaderStyle> <Style TargetType=”DataGridColumnHeader”> <Setter Property=”HorizontalContentAlignment” Value=”Center” /> </Style> </DataGridTextColumn.HeaderStyle>

How to raise an event when DataGrid.ItemsSource is changed

ItemsSource is a dependency property, so it’s easy enough to be notified when the property is changed to something else. You would want to use this in addition to code that you have, not instead of: In Window.Loaded (or similar) you can subscribe like so: var dpd = DependencyPropertyDescriptor.FromProperty(ItemsControl.ItemsSourceProperty, typeof(DataGrid)); if (dpd != null) { … 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

How do I enable text wrapping on all column headers?

Or don’t bother with the primitives in the app.xaml file and do the following (my objects): <DataGrid Name=”WBdataGrid” AutoGenerateColumns=”False” ColumnHeaderHeight=”50″ > <DataGrid.ColumnHeaderStyle> <Style TargetType=”DataGridColumnHeader”> <Setter Property=”ContentTemplate”> <Setter.Value> <DataTemplate> <TextBlock TextWrapping=”Wrap” Text=”{Binding}”></TextBlock> </DataTemplate> </Setter.Value> </Setter> </Style> </DataGrid.ColumnHeaderStyle> <DataGrid.Columns> …

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)