Quantcast
Channel: Caliburn.Micro: Xaml Made Easy
Viewing all articles
Browse latest Browse all 1760

Closed Unassigned: Allow setting of default IsEnabled for elements with a target which is set but not found [319]

$
0
0
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: If a target can't be found nothing should happen. This is the same behavior as with a Binding that cannot be resolved.

Viewing all articles
Browse latest Browse all 1760

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>