0

I have some xaml (for example: <Button IsEnabled="{Binding enableButton}"/>) and I want to bind it to two bools (for instance, enableButton and alsoEnableButton) such that button.IsEnabled = enableButton && alsoEnableButton;, but I want to do this entirely in the xaml. I've seen this question that looks very similar to what I want to do, but I'm not sure how to apply it for my specific situation: WPF binding to two properties - this question addresses setting properties that are not boolean, I want to put a boolean expression in the xaml (ex <Button IsEnabled="true || false"/> or something like that).

How do I bind a xaml property to a boolean expression? Is this possible?

Community
  • 1
  • 1
derekantrican
  • 1,891
  • 3
  • 27
  • 57
  • i think, you cannot, you will need a property with custom getter in your view model – Ehsan Sajjad Jul 11 '16 at 20:23
  • You can't do it entirely in XAML. You can `&&` the bools in your viewmodel, or in a multivalueconverter. You linked an answer to this question. When you tried to apply that answer to doing the exact same thing but with bools, where did you run into trouble? – 15ee8f99-57ff-4f92-890c-b56153 Jul 11 '16 at 20:26
  • @EdPlunkett I know it's *very* similar to that question (please re-read my question, I state it as such). But it's not a duplicate – derekantrican Jul 11 '16 at 20:29
  • 1
    The difference between concatenating two strings and anding two booleans is not that great, even if you do have to cast them all from objects beforehand. – 15ee8f99-57ff-4f92-890c-b56153 Jul 11 '16 at 21:05
  • Yes, work on your abstraction skills, this is most definitely a duplicate. – H.B. Jul 11 '16 at 21:06
  • Not my dv btw. I tried to find the same feature myself a few years ago. – 15ee8f99-57ff-4f92-890c-b56153 Jul 11 '16 at 21:07
  • @H.B. If this *was* a duplicate, then it would result in the same answer. Obviously it's possible with multiple binding in the other case, but not in this case. This is going to result in a different answer (even if that answer is "it's not possible") – derekantrican Jul 11 '16 at 21:07
  • @H.B. Please answer the question and tell me how, then. Because the answer available here isn't working for me: http://stackoverflow.com/questions/23225751/wpf-binding-to-two-properties – derekantrican Jul 11 '16 at 21:11
  • See my concatenation vs `and` comment above. Cast the parameters to bool and do whatever you want with them. – 15ee8f99-57ff-4f92-890c-b56153 Jul 11 '16 at 21:13
  • You can also use a `MultiTrigger` by the way. (Only works for ANDing bindings i think.) – H.B. Jul 11 '16 at 21:22

0 Answers0