Question

I need to be able to "Freeze" a Listbox selection until I clear the User's selection of an item.
I can't seem to find any examples and need a little pointer in the right direction.
I'm in MVVM so I'll probably want to fire a RelayCommand and only enable it when the SelectedIndex is -1.

How do I do this?

Was it helpful?

Solution

You could try to use the Enable propety like:

<Listbox Enabled=False />

If you want, you can bingint this property with another in your code.

Property IsListBoxEnable As Boolean
<Listbox Enabled="{Binding IsListBoxEnable, Mode=TwoWay}" />

and in your code you just modify the value of IsLisBoxEnable.

OTHER TIPS

One way to do this is to data bind IsEnabled to SelectedIndex and then have a converter that returns true only if SelectedIndex is -1

<Listbox IsEnabled={Binding RelativeSource={RelativeSource Self}, 
                    Path=SelectedIndex, Converter=YourConverter} />

For more info on writing YourConverter see this page

In you viewmodel you can have a property for SelectedIndex and then just set it to -1, and the listbox should be enabled again


If you don't want to disable the listbox completely, you can use datavalidation to show an error message under some conditions, here is a good place to get started

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top