Disable ListBox selection through user-interface only

I've got a ListBox that is bound to a custom class:

public class SelectionModel : BaseNotifyProperyChanged
{
    private bool _selected;

    public bool IsSelected
    {
         get { return _selected; }
         set
         {
             _selected = value;
             base.RaisePropertyChanged( "IsSelected" );
         }
    }
    //.... 
}

Through a implementation in the xaml:

<Style TargetType="{x:Type ListBoxItem}">
    <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}"/>
</Style>

I want to disable selection from the user-interface only, keeping the data binding intact, is this possible? I know that I can disable selection by disabling the ListBoxItems with a style, but this makes the binding void.

Edit: It seems to be some confusion, so I'll clarify. I don't want to remove the selection or highlight, I want to be able to select items programmatically, but not through the user-interface. So disabling items or changing highligh colors is not what I'm looking for.

Upvotes: 0

Views: 188

Answers (1)

appa yip yip
appa yip yip

Reputation: 1454

Can't you disable it?

<Style TargetType="{x:Type ListBoxItem}">
    <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=OneWay}"/>
    <Setter Property="IsEnabled" Value="False"/>
</Style>

Upvotes: 1

Related Questions