1
votes

I've a small WPF application(.Net 3.5 :/ ).

In this application I've a listbox, which allows me to select an element to edit on the right part of the application.

If the right part is invalid, I need to prevent the user changing the selection of elements.

I've made a lot of search on this: Some were telling to change the background/brush to make it look like the selection is not possible(but the selection is still possible)

Some other were telling me to update the IsFocusable property of sub elements:

<ListBox itemsSoutces={Binding Test}>
    <ListBoxt.ItemContainerStyle>
        <Style TargetType="{x:Type ListBoxItem}">
            <Setter Property="Focusable" Value="False"/>
        </Style>
    </listBox.ItemContainerStyle>
</ListBox>

The problem with this solution is that this value has to comes from a value of my ViewModel, and I don't know(nor it's possible) to bind the Value of the Style Setter to a property of my ViewModel?

Is it possible? How?

1
I didn't understand what you are trying to achieve. This could be just me being tired, but if this comment gets upvotes - or you don't get answers -, try to clarify that question, possibly with an image or so. What I didn't understand: When will the right part be invalid? The user can't edit anything there. Why don't you prevent selection simply by setting the listbox to disabled (IsEnabled = false)?Daniel Hilgarth
without selection of item in listbox view can you calculate that whether your right view is invalid or not?D J
@DanielHilgarth I feel very stupid right now, I don't know why I didn't thougt to the IsEnabled! If you can post your comment as answer, I will validate it.J4N

1 Answers

1
votes

I would simply disable the listbox if the right part is invalid by setting IsEnabled to false. If your ViewModel contains a corresponding property, you can bind to that:

<ListBox IsEnabled="{Binding IsValid}" ...> ... </ListBox>