<p>I have a rather classic UI situation - two ListBoxes named <code>SelectedItems</code> and <code>AvailableItems</code> - the idea being that the items you have already selected live in <code>SelectedItems</code>, while the items that are available for adding to <code>SelectedItems</code> (i.e. every item that isn't already in there) live in <code>AvailableItems</code>.</p>

<p>Also, I have the <code>&lt;</code> and <code>&gt;</code> buttons to move the current selection from one list to the other (in addition to double clicking, which works fine).</p>

<p>Is it possible in WPF to set up a style/trigger to enable or disable the move buttons depending on anything being selected in either ListBox? <code>SelectedItems</code> is on the left side, so the <code>&lt;</code> button will move the selected <code>AvailableItems</code> to that list. However, if no items are selected (<code>AvailableItems.SelectedIndex == -1</code>), I want this button to be disabled (<code>IsEnabled == false</code>) - and the other way around for the other list/button.</p>

<p>Is this possible to do directly in XAML, or do I need to create complex logic in the codebehind to handle it?</p>

[{'answer_id': 18026, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 7, 'selected': True, 'text': '<p>Here\'s your solution.</p>\n\n<pre><code>&lt;Button Name="btn1" &gt;click me    \n    &lt;Button.Style&gt;        \n        &lt;Style&gt;            \n            &lt;Style.Triggers&gt;                \n                &lt;DataTrigger \n                     Binding ="{Binding ElementName=list1, Path=SelectedIndex}" \n                     Value="-1"&gt;                    \n                    &lt;Setter Property="Button.IsEnabled" Value="false"/&gt;                    \n                &lt;/DataTrigger&gt;                \n            &lt;/Style.Triggers&gt;            \n        &lt;/Style&gt;        \n    &lt;/Button.Style&gt;    \n&lt;/Button&gt;\n</code></pre>\n'}, {'answer_id': 12476073, 'author': 'Karlas', 'author_id': 777313, 'author_profile': 'https://Stackoverflow.com/users/777313', 'pm_score': 6, 'selected': False, 'text': '<p>Less code solution:</p>\n\n<pre><code>&lt;Button Name="button1" IsEnabled="{Binding ElementName=listBox1, Path=SelectedItems.Count}" /&gt;\n</code></pre>\n\n<p>If count is 0 that seems to map to false, > 0 to true.</p>\n'}]
['https://Stackoverflow.com/questions/17906', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2122/']