2016-09-30 7 views
0

저는 C#/WPF 응용 프로그램을 만들고 있습니다. 버튼 클릭만으로 MainViewModel에서 ProcessServiceResponse() 메소드를 호출하고 있습니다. SelectedCountry 속성 값이이 메서드에서 올바르게 설정됩니다. 국가 목록 콤보 상자는 국가 목록도 표시합니다. 하지만 여하튼 국가 드롭 다운 목록에서 선택된 값 (예 : SG)이 보이지 않습니다. 내가 누락 된 부분에 대한 아이디어가 있으십니까? 코드 주위에 다른 세부 정보가 필요한 경우 알려주십시오.콤보 상자에서 선택한 값을 볼 수 없습니다.

감사합니다.

여기 내 코드가 있습니다. 당신이 SELECTEDCOUNTRY에 표시 할 목록 항목 지정의 CountryList를 기입 한 후

MainWindow View: 

<Window 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:MainViewModel="clr-namespace:MyTool.ViewModels" 
     xmlns:ViewModel="clr-namespace:MyTool.ViewModel.Bonds" 
     xmlns:View="clr-namespace:MyTool" x:Class="MyTool.MainWindow" 
     Title="{Binding DisplayName, Mode=OneWay}" ResizeMode="CanMinimize" WindowStartupLocation="CenterScreen" Height="600" Width="1100"> 
    <Window.DataContext> 
     <MainViewModel:MainWindowViewModel/> 
    </Window.DataContext> 


<ComboBox Margin="1,0" ItemsSource="{Binding MyViewModel.CountryList,UpdateSourceTrigger=PropertyChanged}" DisplayMemberPath="Description" SelectedValuePath="Code" SelectedItem="{Binding MyViewModel.SelectedCountry, Mode=TwoWay}" TabIndex="2" Grid.Row="7" Grid.Column="2" HorizontalAlignment="Left" Height="23" VerticalAlignment="Top" Width="180" /> 

MainViewModel: 

public MainWindowViewModel() 
{ 
    MyAttributes = new MyViewModel(); 

} 

public object MyAttributes 
     { 
      get { return m_myViewModel; } 
      set 
      { 
       m_myViewModel = value; 
       OnPropertyChanged("MyAttributes"); 
      } 
     } 

public void ProcessServiceResponse() 

{ 

     var destination = new MyViewModel();/ 
      Type destinationType = destination.GetType(); 

      PropertyInfo[] destinationTypePI = destinationType.GetProperties(); 

      string propertyName = string.Empty; 
      object propertyValue = null; 

      foreach (var pinfo in sourcePI) 
      { 
       propertyName = pinfo.Name.Trim(); 
       var matchingItem = destinationTypePI.ToList().Where(d => d.Name == propertyName); 
       if (matchingItem != null && matchingItem.Count() > 0) 
       { 
        propertyValue = pinfo.GetValue(serviceResponse.lst_DKSecurities[0]); 
        matchingItem.FirstOrDefault().SetValue(destination, propertyValue);      
       } 

      } 

      this.MyAttributes = destination; 

} 

MyViewModel: 

namespace MyTool.ViewModels; 
public class MyViewModel 
{ 

public MyViewModel 
{ 
this.CountryList = GetCountryList(); 
} 

public string SelectedCountry 
     { 
      get 
      { 
       return m_selectedCountry; 
      } 
      set 
      { 
       m_selectedCountry = value; 
      } 
     } 

} 

답변

0

: 당신의 inputs.But에 대한

CountryList = new ObservableCollection<string> {"A", "B", "C"}; 
     SelectedCountry = CountryList[0]; 

<ComboBox ItemsSource="{Binding CountryList, UpdateSourceTrigger=PropertyChanged}"   
       SelectedItem="{Binding SelectedCountry, Mode=TwoWay}" /> 
+0

감사 롬 목록 항목의 값이 실 거예요 작업 두렵다를 그 I 표시하고자하는 것은 MainViewModel의 ProcessServiceResponse() 메소드에서만 사용할 수 있습니다. 그리고 ProcessServiceResponse() 메소드가 호출되기 전에 호출 된 MyViewModel의 생성자에서 국가 목록을 가져옵니다. –

관련 문제