2013-12-17 3 views
3

각 항목 소스에 바인딩 된 여러 개의 Listview가 있습니다. 그러나 나는 오직 1 개의 선택된 항목만을 가지고있다.SelectedItem이 하나만있는 다중 목록보기

그래서 예를 들어 나는 (Monday, Tuesday, ...) 목록 상자가 각각 (MondayList, TuesdayList, ...) 인 항목을 가지고 있습니다. 각 Listviews SelectedItem 속성은 The Property 'CurrentToDo '에 바인드됩니다.

월요일에 하나를 선택한 다음 화요일에 하나를 선택하면 둘 다 선택되는 것이 문제입니다.

모든 목록보기에서 하나의 항목 만 선택할 수 있어야합니다. 도움을 받으십시오.

<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}" /> 

재산권 :

그냥 SelectedValue 대신하여 selectedItem 바인딩 : 여기

private ToDoMod _currentToDo; 

    public ToDoMod CurrentToDo 
    { 
     get { return _currentToDo; } 
     set 
     { 
      _currentToDo= value; 
      if (PropertyChanged != null) 
       PropertyChanged(this, new PropertyChangedEventArgs("CurrentToDo")); 
     } 
    } 

답변

5

는 대답이다.

0

당신은 5 개 이상의 속성을 추가 할 필요가 것 : MondayCurrentToDo, TuesdayCurrentToDo ...

바인드 각 목록보기의 각 재산에 SelectedItem.

각 속성의 세터에서 CurrentToDo를 업데이트하고 다른 목록의 선택을 제거 - 그래서 다음과 같이 표시됩니다 등등 ...

,

물론
private ToDoMod _mondayCurrentToDo; 

public ToDoMod MondayCurrentToDo 
{ 
    get { return _mondayCurrentToDo; } 
    set 
    { 
     _mondayCurrentToDo= value; 
     CurrentToDo = _mondayCurrentToDo; 
     _tuesdayCurrentToDo = null; 
     //TODO: add null setters for all other _<dayOfWeek>CurrentToDo members 


     if (PropertyChanged != null) 
     { 
      PropertyChanged(this, new PropertyChangedEventArgs("MondayCurrentToDo")); 
      PropertyChanged(this, new PropertyChangedEventArgs("TuesdayCurrentToDo")); 
      //TODO: add notificaitons for all other <DayOfWeek>CurrentToDo properties     
     } 
    } 
} 

, 방법으로이 문제를 리팩토링

관련 문제