CreateColumnsCommand cannot be triggered

Sep 22, 2012 at 12:54 PM

Hi,

This is a great example. But I downloaded the source and cannot execute CreateColumnsCommand in EventTrigger AutoGeneratingColumn.

Thanks!

Tony

Oct 12, 2012 at 12:23 PM
Edited Oct 12, 2012 at 12:25 PM

Based on http://stackoverflow.com/questions/3881904/mvvm-wpf-datagrid-autogeneratingcolumn-event i've found this workaround:

- added View.xaml.cs to the project BondModule under the folder Views

- added an event handler for the event AutoGeneratingColumn of the DataGrid

  Modifed View.xaml (added code in bold)

<DataGrid
    HorizontalScrollBarVisibility="Visible"
    VerticalScrollBarVisibility="Visible"
    MaxHeight="{x:Static AttachedProperty:WindowProperties.OneHalfHeightNoBorder}"
    Name="MainGrid"
    ItemsSource="{Binding Entities}"
    AutoGenerateColumns="true"
    AutoGeneratingColumn="MainGrid_AutoGeneratingColumn"
>

  Added to View.xaml.cs

private void MainGrid_AutoGeneratingColumn(object sender, System.Windows.Controls.DataGridAutoGeneratingColumnEventArgs e)
{
	var context = this.DataContext as BondModule.ViewModels.BondViewModel;
	var args = new WPF.RealTime.Infrastructure.AttachedCommand.EventToCommandArgs(sender, context.CreateColumnsCommand, null, e);
	context.CreateColumnsCommand.Execute(args);
}

Did the same for the FutureModule.

This worked for me.

Hope this helps.

 

Vincenzo.

Oct 19, 2012 at 2:03 PM

Hi Vincenzo,

It works great. Many thanks!

Tony