Hi Greg, Instead of binding the click of a datagrid row you have other options. For example, you could bind the "selected row" to a property on your view model. When that collection changes you can raise a method in the view model (you can track the collection changing by handling the relevant events on ObservableCollection or BindingList).
However I think in your case a command parameter is all that is needed, where the command parameter is also bound to the current item in the itemsource. But the more you talk about this, it seems to me you have a view model, not a controller. Maybe I am missing something... anyway I find that MVVM fixes all those binding issues. Cheers, Steve From: [email protected] [mailto:[email protected]] On Behalf Of Greg Keogh Sent: Monday, 26 July 2010 10:06 PM To: 'ozWPF' Subject: RE: Commands to the controller Folks - I found the basic code necessary to get simple command handler code out of the control code-behind. I found a copy of RelayCommand and use it like below (abbreviated). The important bits are highlighted. I found a few versions of RelayCommand on the web, some are mutated from the original to be generic and some handle arguments. I think it originally came from the Microsoft DelegateCommand in their framework. One remaining problem is the "lifetime" of the view and its controller. It's a "chicken and egg problem". I'm studying this problem at the moment and I might post about it later. I have been trying to remove as much code as possible from the view, but as I progress the binding becomes trickier and I feel like I'm solving a progressively more difficult IQ test. For example, I now have to code some binding on a grid so that when a row is double-clicked, the bound method in the controller is passed the row data. Then I have to deal with loading trees. It gets harder to finding more and more astonishingly obscure ways of solving binding conundrums. History books will tell us that MVVM and binding was an artificial puzzle that was created to confound developers in the early part of the 21st century. Greg The Control XAML <ctls:BaseWpfControl> <ctls:BaseWpfControl.Resources> <ctls:LogoffController x:Key="controller"/> </ctls:BaseWpfControl.Resources> <Grid x:Name="LayoutRoot"> <Button x:Name="btnLogin" Content="Login" Command="{Binding Path=LoginAttemptCommand, Source={StaticResource controller}}"> </Button> </Grid> </ctls:BaseWpfControl> The Controller private RelayCommand<object> _logonAttemptCommand; public ICommand LoginAttemptCommand { get { if (_logonAttemptCommand == null) { _logonAttemptCommand = new RelayCommand<object>((param) => InnerLoginAttempt(param)); } return _logonAttemptCommand; } } private void InnerLoginAttempt(object param) { // Login attempt command processing here (send a message) }
_______________________________________________ ozwpf mailing list [email protected] http://prdlxvm0001.codify.net/mailman/listinfo/ozwpf
