2010-05-24 2 views
0

wpf를 배우고 바인딩 작업 방식을 이해하는 연습으로 저는 작동하는 예제가 있습니다. 그러나 요청시로드하려고 할 때 나는 비참하게 실패합니다. 내가 요구에로드하면 나는 그것이 비참하게 실패의 모든 작품을 모두 하나의로드를 갈 경우MasterDetails 요구시로드 중

나는 기본적으로 3 등급 국가 시티 호텔

있습니다. 무엇이 잘못 되었나요?

작품

 <Window x:Class="MasterDetailCollectionViewSource.CountryCityHotelWindow" 
       xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
       xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
       Title="CountryCityHotelWindow" Height="300" Width="450"> 
      <Window.Resources> 
       <CollectionViewSource Source="{Binding}" x:Key="cvsCountryList"/> 
       <CollectionViewSource Source="{Binding Source={StaticResource cvsCountryList},Path=Cities}" x:Key="cvsCityList"/> 
       <CollectionViewSource Source="{Binding Source={StaticResource cvsCityList},Path=Hotels}" x:Key="cvsHotelList"/> 
      </Window.Resources> 
      <Grid> 
       <Grid.ColumnDefinitions> 
        <ColumnDefinition/> 
        <ColumnDefinition/> 
        <ColumnDefinition/> 
       </Grid.ColumnDefinitions> 
       <Grid.RowDefinitions> 
        <RowDefinition Height="Auto"/> 
        <RowDefinition/> 
       </Grid.RowDefinitions> 
       <TextBlock Grid.Column="0" Grid.Row="0" Text="Countries"/> 
       <TextBlock Grid.Column="1" Grid.Row="0" Text="Cities"/> 
       <TextBlock Grid.Column="2" Grid.Row="0" Text="Hotels"/> 

       <ListBox Grid.Column="0" Grid.Row="1" Name="lstCountries" ItemsSource="{Binding Source={StaticResource cvsCountryList}}" DisplayMemberPath="Name" SelectionChanged="OnSelectionChanged"/> 
       <ListBox Grid.Column="1" Grid.Row="1" Name="lstCities" ItemsSource="{Binding Source={StaticResource cvsCityList}}" DisplayMemberPath="Name" SelectionChanged="OnSelectionChanged"/> 
       <ListBox Grid.Column="2" Grid.Row="1" Name="lstHotels" ItemsSource="{Binding Source={StaticResource cvsHotelList}}" DisplayMemberPath="Name" SelectionChanged="OnSelectionChanged"/> 
      </Grid> 
     </Window> 

그러나 내가 요구에 물건을 가져 오는 다음을 추가 한,

XAML은 상기와 동일 작동하지 않습니다. 한 번에 모든 것을로드하고 코드 숨김이 아닌 다른 국가와 반대로 국가를로드합니다.

public CountryCityHotelWindow() 
    { 
     InitializeComponent(); 

     //Load only country Initially 
     lstCountries.ItemsSource=Repository.GetCountries(); 
     DataContext = lstCountries; 
    } 

    private void OnSelectionChanged(object sender, SelectionChangedEventArgs e) 
    { 
     var lstBox = (ListBox)e.OriginalSource; 
     switch (lstBox.Name) 
     { 
      case "lstCountries": 
       var country = lstBox.SelectedItem as Country; 
       if (country == null) return; 
       lstCities.ItemsSource = Repository.GetCities(country.Name); 
       break; 
      case "lstCities": 
       var city = lstBox.SelectedItem as City; 
       if (city == null) return; 
       lstHotels.ItemsSource = Repository.GetHotels(city.Name); 
       break; 
      case "lstHotels": 
       break; 
     } 
    } 

내가 뭘하고 있니? 감사합니다.

답변

1

그냥 모든 것을 작동하게 만들었습니다. 내가

누락 된 IsSynchronizedWithCurrentItem = "참"

espected으로 지금이 작동합니다.

관련 문제