0

我在 ListView 中托管了一个 ComboBox,我需要在 CombBox 中进行更改以更新 ListView 绑定到的支持类。

这是我的数据模板

<DataTemplate x:Key="Category">
    <ComboBox IsSynchronizedWithCurrentItem="False" 
              Style="{StaticResource DropDown}" 
              ItemsSource="{Binding Source={StaticResource Categories}}"
              SelectedValuePath="Airport"
              SelectedValue="{Binding Path=Category}"
              />
    </DataTemplate>

这是列表视图。ListView 的 ItemSource 是 Airports 的集合,并在后面的代码中设置,并且有一个名为 Category 的属性,我需要组合框来更新它。

<ListView.View>
            <GridView>
                <GridViewColumn DisplayMemberBinding="{Binding Path=Name}" Header="Airport" Width="100" />
                <GridViewColumn Header="Category" Width="100"  CellTemplate="{StaticResource Category}" />
            </GridView>
        </ListView.View>
4

2 回答 2

1

你为什么设置SelectedValuePath在你的ComboBox? 没有看到你的数据结构很难说,但这对我来说看起来不对。

于 2008-12-24T18:23:20.123 回答
0

这是支持 ComboBox 和 ListView 的数据。

Imports System.Collections.ObjectModel

班级窗口1

Public Airports As New ObservableCollection(Of Airport)
Public Sub New()
    ' This call is required by the Windows Form Designer.
    InitializeComponent()

    '*************************
    'Dummy data for testing


    Dim anAirports As New Airport
    anAirports.Name = "ABC"
    anAirports.Category = "AA"

    Airports.Add(anAirports)

    anAirports = New Airport
    anAirports.Name = "DEF"
    anAirports.Category = "BB"

    Airports.Add(anAirports)
    '*************************
    'Bind the airports to the list for display
    lstCategories.ItemsSource = Airports

End Sub

结束类

公共类机场

''' <summary>
''' Name of the Airport
''' </summary>
''' <remarks></remarks>
Private mName As String
Public Property Name() As String
    Get
        Return mName
    End Get
    Set(ByVal value As String)
        mName = value
    End Set
End Property

''' <summary>
''' Describes the type airport and is selected from a combobox
''' </summary>
''' <remarks></remarks>
Private mCategory As String
Public Property Category() As String
    Get
        Return mCategory
    End Get
    Set(ByVal value As String)
        mCategory = value
    End Set
End Property

结束类

''' ''' 要在 ComboBox 中显示的项目 ''' ''' 公共类类别

Inherits ObservableCollection(Of String)

Public Sub New()
    Me.Add("AA")
    Me.Add("BB")

End Sub

结束类

于 2008-12-24T18:58:36.370 回答