My scenario: I've got a ViewModel which is a Conductor.Collection.OneAction, and in the corresponding View I have a button which I want to bind to a target in the ViewModel's ActiveItem.
The trick is that not all of the elements in the ViewModel's Items collection have the supplied target, and I want to disable the button when that target is not found.
The following gets me most of the way there:
```
<Button cal:Action.TargetWithoutContext="{Binding ActiveItem}" cal:Message.Attach="MethodName" IsEnabled="False"/>
```
The catch is that, if ActiveItem changes from an item which has MethodName to one that does not, there's no way to make the button disable itself, as the IsEnabled property will remain at its last value.
The attached patch adds a static property called DefaultIsEnabledIfTargetNotFound to ActionMessage. If set, it forces the value of IsEnabled for elements for which a target has been set, but where that target can't be found, to the value of the property. The default behaviour is not changed - only if this property is set does the new behaviour apply.
I can reword the patch if you have any comments.
Thanks!
Antony
Comments: You can do your changes by overriding _ApplyAvailabilityEffect()_ without changing Caliburn.Micro source. Just do this in your bootstrapper: ``` C# var applyAvailabilityEffectBase = ActionMessage.ApplyAvailabilityEffect; ActionMessage.ApplyAvailabilityEffect = context => { //TODO: do anything you want to change here return applyAvailabilityEffectBase(context); }; ```
The trick is that not all of the elements in the ViewModel's Items collection have the supplied target, and I want to disable the button when that target is not found.
The following gets me most of the way there:
```
<Button cal:Action.TargetWithoutContext="{Binding ActiveItem}" cal:Message.Attach="MethodName" IsEnabled="False"/>
```
The catch is that, if ActiveItem changes from an item which has MethodName to one that does not, there's no way to make the button disable itself, as the IsEnabled property will remain at its last value.
The attached patch adds a static property called DefaultIsEnabledIfTargetNotFound to ActionMessage. If set, it forces the value of IsEnabled for elements for which a target has been set, but where that target can't be found, to the value of the property. The default behaviour is not changed - only if this property is set does the new behaviour apply.
I can reword the patch if you have any comments.
Thanks!
Antony
Comments: You can do your changes by overriding _ApplyAvailabilityEffect()_ without changing Caliburn.Micro source. Just do this in your bootstrapper: ``` C# var applyAvailabilityEffectBase = ActionMessage.ApplyAvailabilityEffect; ActionMessage.ApplyAvailabilityEffect = context => { //TODO: do anything you want to change here return applyAvailabilityEffectBase(context); }; ```