Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple Listviews with only one SelectedItem

I have multiple Listviews each binded with their own itemsource. But i only have 1 Selected Item.

So for example i have 5 listboxes (Monday, Tuesday, ...) each of them with their own itemssource (MondayList, TuesdayList, ...). Each of these Listviews SelectedItem property is binded to The Property 'CurrentToDo'.

The problem is that if i select one in the Monday and then select one in Tuesday they are both selected.

So only one item should be able to be selected throughout all the listviews, please help.

<UserControl.Resources>        
    <Style x:Key="ListViewItemStyleToDo" TargetType="{x:Type ListViewItem}">
        <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}"/>
    </Style>

    <GridView x:Key="ViewBase1" x:Shared="False" >
        <GridViewColumn Header="" Width="30">
            <GridViewColumn.CellTemplate>
                <DataTemplate>
                    <CheckBox IsChecked="{Binding IsSelected, Mode=TwoWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListViewItem}}}" />
                </DataTemplate>
            </GridViewColumn.CellTemplate>
        </GridViewColumn>
        <GridViewColumn Header="Subject" Width="auto" DisplayMemberBinding="{Binding Subject}" />
    </GridView>
</UserControl.Resources>

<ListView Grid.Row="1"  ItemsSource="{Binding MondayList}" SelectedItem="{Binding CurrentToDo, Mode=TwoWay}" SelectionMode="Single" ItemContainerStyle="{DynamicResource ListViewItemStyleToDo}" View="{DynamicResource ViewBase1}" />

<ListView Grid.Row="3"  ItemsSource="{Binding TuesdayList}" SelectedItem="{Binding CurrentToDo,Mode=TwoWay}" SelectionMode="Single" ItemContainerStyle="{DynamicResource ListViewItemStyleToDo}" View="{DynamicResource ViewBase1}"  />

Property:

    private ToDoMod _currentToDo;

    public ToDoMod CurrentToDo
    {
        get { return _currentToDo; }
        set
        {
            _currentToDo= value;
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs("CurrentToDo"));
        }
    }
like image 808
Sam_vdd Avatar asked Dec 17 '13 14:12

Sam_vdd


1 Answers

Here is the answer:

Just bind to SelectedValue instead of SelectedItem.

like image 83
Sam_vdd Avatar answered Oct 28 '22 06:10

Sam_vdd