如何在ListView中托管此ComboBox以更新我的收藏?

时间:2008-12-24 17:42:55

标签: wpf data-binding binding

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

这是我的DataTemplate

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

这是Listview。 ListView的ItemSource是一个机场的集合,在后面的代码中设置,并有一个名为Category的属性,我需要组合框进行更新。

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

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

以下是支持ComboBox和ListView的数据。

Imports System.Collections.ObjectModel

类Window1

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

结束班

Public Class Airport

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

结束班