Question

I am using Silverlight Application in that I am using Datagrid and binding Data based on Observable Collection, but when I am trying to Bind the Observable Collection to Dropdown it's not binding, do we need to write code to Bind in the xaml Code behind.

My Code :

<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>

ViewModel :

Public LabValidatedList As New List(Of String)() From { _
    "Yes", _
    "No"
}
Était-ce utile?

La solution

In order to be usable as the source of a binding, LabValidatedList has to be a public property, not a field:

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 

Sorry if the above does not compile immediately, but VB is not my language. Note also that a List(Ofd String) is not an ObservableCollection.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top