I'm working on codeless WPF + CSLA Business logic.
When I tried to create a WPF Close button to close the screen, the button stays disabled. I'm struggling to work out if the CSLA WPF handler is doing this or I've not set this up correctly. Does anyone know how to resolve this?
<csla:ObjectStatus >
<csla:Authorizer Name="AuthPanel">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
<CheckBox
IsEnabled="False"
IsChecked="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=csla:ObjectStatus, AncestorLevel=1}, Path=IsSavable}">IsSavable</CheckBox>
<CheckBox
IsEnabled="False"
IsChecked="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=csla:ObjectStatus, AncestorLevel=1}, Path=IsValid}">IsValid</CheckBox>
<CheckBox
IsEnabled="False"
IsChecked="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=csla:ObjectStatus, AncestorLevel=1}, Path=IsDirty}">IsDirty</CheckBox>
<CheckBox
IsEnabled="False"
IsChecked="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=csla:ObjectStatus, AncestorLevel=1}, Path=IsNew}">IsNew</CheckBox>
<Button
Content="Save"
Command="ApplicationCommands.Save"
CommandTarget="{Binding Source={StaticResource SoftwareOptions}, Path=CommandManager, BindsDirectlyToSource=True}"
HorizontalAlignment="Left" IsDefault="True"/>
<Button
Content="Undo"
Command="ApplicationCommands.Undo"
CommandTarget="{Binding Source={StaticResource SoftwareOptions}, Path=CommandManager, BindsDirectlyToSource=True}"
HorizontalAlignment="Left"
IsCancel="True"/>
<!--TODO: Review why Command="ApplicationCommands.Close" can be used for close button (codeless). Button is alway disabled. -->
<Button Name="CloseButton"
Content="E_xit"
HorizontalAlignment="Left"
IsEnabled="True" />
</StackPanel>
</csla:Authorizer>
</csla:ObjectStatus>
Since you aren't specifying an explicit command target, the command looks up through the visual tree for something that can handle the command. Unless you have implemented methods to handle the command somewhere higher in the visual tree (usually in the code-behind the form) then the button will never enable because there's nothing out there to handle the command.
If you want to use commanding like that, it is totally standard WPF, and you should read up on its usage in MSDN or in a WPF book that covers commanding.
Cheers Rocky.
I've only just discovered Commands when you put them into the CSLA (Your Blog). Adam Nathans WPF book coved this exact topic on Page 75. I must have glossed over this while reviewing commands.
Found your references in csla38cs\Csla\Wpf\CslaDataProviderCommandManager.cs
WPF is an interesting beast.
Copyright (c) Marimer LLC