Your idea is great, after my test it works. Here are the steps.
1.Create the WPF Custom Control Library
named WpfCustomControlLibrary2
.
2.Right Click CustomControl1.cs
and selected Rename
, then edit the class named MyComboBox
.
3.Complete code for WpfCustomControlLibrary2
.
You could add modifier public
to MyComboBox
class MyComboBox : DependencyObject ---> public class MyComboBox : DependencyObject
Code.
4.Add reference WpfCustomControlLibrary2(dll) for VBproject.
5.VB project:
MainWindow.xaml:
MainWindow.vb:
Imports System.Runtime.CompilerServices
Imports System.ComponentModel
Imports System.Collections.ObjectModel
Partial Public Class MainWindow
Inherits Window
Public Sub New()
InitializeComponent()
Dim vm As FilterViewModel = New FilterViewModel()
Me.DataContext = vm
End Sub
End Class
Public Class FilterViewModel
Implements INotifyPropertyChanged
Private _dataSource As ObservableCollection(Of String)
Public Property DataSource As ObservableCollection(Of String)
Get
Return _dataSource
End Get
Set(ByVal value As ObservableCollection(Of String))
_dataSource = value
OnPropertyChanged("ListOfCountry")
End Set
End Property
Public Sub New()
_dataSource = New ObservableCollection(Of String)()
_dataSource.Add("Beijing")
_dataSource.Add("New York")
_dataSource.Add("Paris")
_dataSource.Add("Shanghai")
_dataSource.Add("London")
_dataSource.Add("Nanjing")
End Sub
Private Event INotifyPropertyChanged_PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
Friend Sub OnPropertyChanged(<CallerMemberName> ByVal Optional propName As String = "")
RaiseEvent INotifyPropertyChanged_PropertyChanged(Me, New PropertyChangedEventArgs(propName))
End Sub
End Class
The result:
----------------------------------------------------------------------------
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.