2013-01-06 3 views
6

에 존재하지 않는 무언가에 바인딩 된 모든 항목 내가 다른 ItemsSource로하지만 같은 속성에 바인딩 SelectedItem 두 개의 목록이 - "이름을".의 선택을 해제 selectedItem 그가 목록

먼저 왼쪽 목록의 항목 "c"가 선택되도록 오른쪽 목록에서 항목 "c"를 선택합니다.

오른쪽 목록에서 다른 항목을 선택했지만 왼쪽 목록의 "c"가 여전히 선택되었습니다. 왜 그 일을하는지 이해하지만 오른쪽 목록에서 "c"를 선택 취소 할 수 있습니까?

enter image description here

XAML :

<Grid> 
    <Grid.ColumnDefinitions> 
     <ColumnDefinition /> 
     <ColumnDefinition /> 
    </Grid.ColumnDefinitions> 

    <ListView SelectedItem="{Binding Name}" ItemsSource="{Binding lstNames1}"/> 
    <ListView SelectedItem="{Binding Name}" ItemsSource="{Binding lstNames2}" Grid.Column="1"/> 
</Grid> 

코드 뒤에 : 당신이 SelectedItem이 당신이 원하는 방법을 작동합니다 SelectedValue 결합을 전환하면

public partial class selected : Window 
{ 
    public ObservableCollection<string> lstNames1 { get; set; } 
    public ObservableCollection<string> lstNames2 { get; set; } 

    public string Name { get; set; } 


    public selected() 
    { 
     Names1 = new ObservableCollection<string> {"a1", "b1", "c"}; 
     Names2 = new ObservableCollection<string> { "a2", "b2", "c" }; 
     InitializeComponent(); 
     DataContext = this; 
    } 
} 
+0

그래서 당신은 여전히 ​​싶다 "c"를 만들

<ListView SelectedValue="{Binding Name}" ItemsSource="{Binding lstNames1}" /> <ListView SelectedValue="{Binding Name}" ItemsSource="{Binding lstNames2}" Grid.Column="1"/> 

희망은 두 목록에서 선택하지만 항목이 하나 개의 목록에있는 경우에서 selction을 취소합니다 다른 사람? –

+0

sa_ddam213 - 정확히! :) – Erez

+0

창에는 이미 [Name] (http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.name.aspx) 속성이 있습니다. 따라서 새로 생성 된 것은 기존의 것과 충돌합니다. Name 속성에 변경 알림이 없습니다. – Clemens

답변

7

SelectedItem 그 때문에 삭제되지 않는다 null으로 설정되지 않습니다. 다른 목록에서 값이으로 설정 되었기 때문입니다.은 항목을 찾아야하거나 목록에있는 SelectedItem을 지울 때마다 약간 다르게 작동합니다. 의미 :

enter image description here enter image description here

+0

벨리 시모, 고마워. – Erez