2013-10-31 1 views
0

VB.Net WPF 응용 프로그램에 ComboBox이 있습니다. 에서 VB.Net의 ComboBox에 바인딩 목록 WPF 응용 프로그램

<ComboBox HorizontalAlignment="Left" Margin="77,49,0,0" VerticalAlignment="Top" Width="120" ItemsSource="{Binding Path=Server.RecipeList()}" DisplayMemberPath="RecipeID" SelectedValuePath="RecipeID"/> 

코드 숨김, 내가 서버라는 클래스 변수가 있습니다

Private mRecipeList As New List(Of Recipe) 

그리고 내 기본 생성자 : 내 서버 개체에서

Public Server As BatchServer = New BatchServer 

을, 나는 List이 서버는

Public Sub New() 
    Server = New BatchRemote.RemoteSupport 
    PopulateRecipeList() 
End Sub 

ListComboBox에 바인딩하고 싶으므로 내 목록에 각 래서 피의 RecipeID가 표시되어야합니다. 첫 번째 코드 블록에서와 마찬가지로 내 데이터 바인딩이 보이지만 응용 프로그램을 실행할 때 ComboBox은 항상 비어 있습니다.

내가 뭘 잘못하고 있니?

답변

0

첫째, 당신은 제대로 INotifyPropertyChanged interface 구현하는 public PropertyServer를 선언해야합니다. 그런 다음 RecipeList에 대해서도 동일한 작업을 수행해야합니다. 그럼 당신은 이런 Bind 할 수 있어야한다 :

<ComboBox HorizontalAlignment="Left" Margin="77,49,0,0" VerticalAlignment="Top" 
Width="120" ItemsSource="{Binding Path=Server.RecipeList}" DisplayMemberPath="RecipeID" 
SelectedValuePath="RecipeID" /> 
0

당신의 코드가 작동하지 않는 간단한 목록에 결합하고 있으며, 추가 또는 예를 들어 일부 목록 요소를 제거 할 때 너무 속성 밤은 업데이트 때문이다.

창에서 ObservableCollection에 read more here로 auxiliar 목록을 선언하고 같은 콤보 바인딩 : 다음

Private Property auxRecipeList As New ObservableCollection(Of Recipe) 

XAML에서 수행과 같은 바인딩 :

<ComboBox HorizontalAlignment="Left" Margin="77,49,0,0" VerticalAlignment="Top" Width="120" ItemsSource="{Binding auxRecipeList, Mode=TwoWay, UpdateSourcetrigger=PropertyChanged}" DisplayMemberPath="RecipeID" SelectedValuePath="RecipeID"/> 
관련 문제