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