Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Command inside WPF 4 DataGrid RowDetailsTemplate Not firing

$
0
0

Hi all,

I am using VS2010 WPF4 + Prism 2.2 to build my application. In oder to demo the issue, I built a very simple application here:

The Xaml of window (MainWindow.xaml), I defined a DataGrid and a button. I bind command of button inside row details to a DelegateCommand defined in ModelView, I also bind button (below the DataGrid) to another command.

<Windowx:Class="WpfApplication1.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"Title="MainWindow"Height="350"Width="525"><Grid><Grid.RowDefinitions><RowDefinition></RowDefinition><RowDefinition></RowDefinition></Grid.RowDefinitions><DataGridAutoGenerateColumns="False"ItemsSource="{Binding Customers}"><DataGrid.Columns><DataGridTextColumnHeader="ID"IsReadOnly="True"Binding="{Binding Path=ID}"/></DataGrid.Columns><DataGrid.RowDetailsTemplate><DataTemplate><ButtonCommand="{Binding Test1Command}"CommandParameter="{Binding Path=ID}">Update</Button></DataTemplate></DataGrid.RowDetailsTemplate></DataGrid><ButtonGrid.Row="1"Command="{Binding Test2Command}">Test 2</Button></Grid></Window>

The code of the Xaml (MainWindow.xaml.cs) is

using System.Windows;namespace WpfApplication1 {publicpartialclass MainWindow : Window {public MainWindow() {
			InitializeComponent();this.DataContext = new TestViewModel();
		}
	}
}

The view model class (TestViewModel.cs) is

using System;using System.Collections.ObjectModel;using System.ComponentModel;using Microsoft.Practices.Composite.Presentation.Commands;namespace WpfApplication1 {publicclass TestViewModel {public TestViewModel() {this.customers = new ObservableCollection<Customer>();this.customers.Add(new Customer() { ID = 1 });this.customers.Add(new Customer() { ID = 2 });this.customers.Add(new Customer() { ID = 3 });this.customers.Add(new Customer() { ID = 4 });this.test1Command = new DelegateCommand<int>(Test1CommandExecuted, Test1CommandCanExecute);this.test2Command = new DelegateCommand<object>(Test2CommandExecuted, Test2CommandCanExecute);
		}private DelegateCommand<int> test1Command;public DelegateCommand<int> Test1Command {get {return test1Command;
			}
		}privatevoid Test1CommandExecuted(int parameter) {return;
		}privatebool Test1CommandCanExecute(int parameter) {returntrue;
		}private DelegateCommand<object> test2Command;public DelegateCommand<object> Test2Command {get {return test2Command;
			}
		}privatevoid Test2CommandExecuted(object parameter) {return;
		}privatebool Test2CommandCanExecute(object parameter) {returntrue;
		}private ObservableCollection<Customer> customers;public ObservableCollection<Customer> Customers {get {returnthis.customers;
			}set {this.customers = value;
			}
		}
	}publicclass Customer : INotifyPropertyChanged {privateint id;publicint ID {get {return id;
			}set {
				id = value;
				notifyPropertyChanged("ID");
			}
		}publicevent PropertyChangedEventHandler PropertyChanged;protectedvoid notifyPropertyChanged(String info) {if (PropertyChanged != null) {
				PropertyChanged(this, new PropertyChangedEventArgs(info));
			}
		}
	}
}

I set break point to both Test1CommandExecuted and Test2CommandExecuted. I lauch the application and I click on botton below DataGrid, I could capture the event is fired; I click the button insude row details and I don't capture any event fired.

Anybody has clue what is wrong with my code?

Thanks

Hardy


Welcome to help me with my open source project at http://code.google.com/p/batch-image-watermark-processor/

Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>