我在VSIX项目中遇到了一个Combobox问题。我正在使用MVVM模式。
<ComboBox
ItemsSource="{Binding ProjectList, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
DisplayMemberPath="Name"
IsSynchronizedWithCurrentItem="True"
Style="{StaticResource MyStyle}"
SelectedValue="{Binding Project, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
这是我的Combobox,它是项目列表的bindet。 SelectedValue是列表的一个项目。像这样:
ProjectList = New List(Of Project)(Helper.GetFormsProjects())
If ProjectList.Count > 0 Then
Project = ProjectList(0)
End If
但如果我在Combobox中选择另一个值,它就不会调用项目属性的setter。
以下是属性:
Public Property _projectList As List(Of Project)
Public Property ProjectList As List(Of Project)
Get
Return _projectList
End Get
Set(value As List(Of Project))
_projectList = value
OnPropertyChanged()
End Set
End Property
Public Property _project As Project
Public Property Project As Project
Get
Return _project
End Get
Set(value As Project)
_project = value
OnPropertyChanged()
End Set
End Property