2011-03-15 96 views
0

子對象結合到ListView我有一個ObservableCollection測量對象問題在VB.Net

Dim measurement As New Collections.ObjectModel.ObservableCollection(Of Measurement) 

在哪裏測量是

Public Class Measurement 
    Public Property Value As Single 
    Public Property Unit As String 
    Public Property Enviroment As Enviroment 
End Class 

與環境中(簡化的)

Public Class Enviroment 
    Public Equipment As String 
End Class 

現在我把這個Collection綁定到ListView

<ListView ItemsSource="{Binding}"> 
    <ListView.Resources> 
     <my:SingleToStringConverter x:Key="singleToString"></my:SingleToStringConverter> 
     <DataTemplate x:Key="ValueTemplate"> 
      <TextBlock Text="{Binding Value, Converter={StaticResource singleToString}}"></TextBlock> 
     </DataTemplate> 
    </ListView.Resources> 
    <ListView.View> 
     <GridView> 
      <GridViewColumn Header="Value" CellTemplate="{StaticResource ValueTemplate}"></GridViewColumn> 
      <GridViewColumn Header="Unit" DisplayMemberBinding="{Binding Unit}"></GridViewColumn> 
      <GridViewColumn Header="Enviroment" DisplayMemberBinding="{Binding Enviroment.Equipment}"></GridViewColumn> 
     </GridView> 
    </ListView.View> 
</ListView> 

待完成;轉換器是:

Public Class SingleToStringConverter 
    Implements IValueConverter 

    Public Function Convert(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.Convert 
    Return CSng(value).ToString(Globalization.CultureInfo.InvariantCulture) 
    End Function 

    Public Function ConvertBack(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.ConvertBack 
    Return CSng(value.ToString) 
    End Function 
End Class 

但ListView不顯示任何SubObject Eviroment的屬性。它不支持INotifyPropertyChanged,但我確信它在添加到集合之前就已存在。但現在有值顯示。 任何人都可以請幫忙嗎?

+0

我正在嘗試做類似的事情。你能告訴我:你把這個XML放在哪裏? – 2012-09-21 09:03:49

回答

3

您嘗試綁定到字段而不是屬性。我認爲你的Enviroment-Object應該看起來像這樣:

Public Class Enviroment 
    Public **Property** Equipment As String 
End Class 

你不能綁定到公共字段。