RoutedEvent argument always null

Topics: Prism v2 - WPF 3.5
Dec 3, 2009 at 7:52 AM

  I have a view which lists all product items in a list box and upon selection of which I want ot show a product edit window.  I have wired the listbox's SelectionChanged Event to the view model.
I am able to capture the event in the viewmodel, but the argument (selectedProduct) is always null.
What am I doing wrong?

The view is defined thus:

          attachedcommand:CommandBehavior.TheCommandToRun="{Binding Path=SelectProductCommand}"
          attachedcommand:CommandBehavior.CommandParameter="{Binding ElementName=lbxProduct, Path=SelectedItem}"
            x:Name="lbxProduct" Grid.ColumnSpan="2" ScrollViewer.VerticalScrollBarVisibility="Visible"
                 ItemsSource="{Binding Path=ProductList}" Margin="8,36,8,4" Grid.RowSpan="2">
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="#FFAEB9A3"/>
                    <GradientStop Color="#FF83A985" Offset="0.375"/>
                    <GradientStop Color="#FF719778" Offset="0.379"/>
                    <GradientStop Color="#FF61846E" Offset="1"/>
I have the corresponding ViewModel defined thus:
 public class ProductCollectionViewModel : ViewModelBase
        private ObservableCollection<Product> productList;
        public ICommand SelectProductCommand { get; set; }
        public EventHandler<DataEventArgs<Product>> ProductSelected = delegate {};
        private IRegionManager regionManager;
        private IUnityContainer container;
        private IEventAggregator eventAggregator;
        public ObservableCollection<Product> ProductList
            get { return productList; }
                if (productList != value)
                    productList = value;
                    OnPropertyChanged(this, "ProductList");
        public ProductCollectionViewModel(IProductDataService dataService, IEventAggregator eventAggregator, IRegionManager regionManager, IUnityContainer container)
            this.regionManager = regionManager;
            this.container = container;
            this.eventAggregator = eventAggregator;
            this.SelectProductCommand = new DelegateCommand<Product>(this.SelectProduct);
            List<Product> prodList = dataService.GetAllProducts();
            productList = new ObservableCollection<Product>(prodList);

        private void SelectProduct(Product selectedProduct)
            IRegion mainRegion = regionManager.Regions["MainRegion"];
            var wsView = mainRegion.GetView("ProductWorkspaceView");
            if (wsView == null)
                wsView = container.Resolve<IProductWorkspaceView>();
                mainRegion.Add(wsView, "ProductWorkspaceView");
            ProductSelected(this, new DataEventArgs<Product>(selectedProduct));