2013-07-23 47 views
0

我使用Silverlight應用程序,我使用Datagrid並綁定基於Observable集合的數據,但是當我試圖將Observable集合綁定到Dropdown它沒有約束力時,我們是否需要編寫代碼來綁定後面的xaml代碼。綁定列表到下拉在SIlverlight不起作用

我的代碼:

<sdk:DataGridTemplateColumn Header="lab Validated?" CanUserSort="True"> 
    <sdk:DataGridTemplateColumn.CellTemplate> 
     <DataTemplate> 
      <Grid> 
       <ComboBox Height="Auto" HorizontalAlignment="Left" 
          Name="cboLabValidated" VerticalAlignment="Center" Width="80" 
          ItemsSource="{Binding Path=LabValidatedList}"> 
       </ComboBox> 
      </Grid> 
     </DataTemplate> 
    </sdk:DataGridTemplateColumn.CellTemplate> 
</sdk:DataGridTemplateColumn> 

視圖模型:

Public LabValidatedList As New List(Of String)() From { _ 
    "Yes", _ 
    "No" 
} 

回答

1

爲了可用作結合的來源,LabValidatedList必須是一個公共屬性,而不是一個場:

Private labValidatedListValue As New List(Of String)() From { _ 
    "Yes", _ 
    "No" 
} 

Public Property LabValidatedList() As List(Of String) 
    Get 
     Return Me.labValidatedListValue 
    End Get 

    Set(ByVal value As List(Of String)) 
     Me.labValidatedListValue = value 
    End Set 
End Property 

對不起,如果以上不立即編譯,但VB不是我的語言。還請注意,List(Ofd String)不是ObservableCollection