Hi,@ Roger Schlueter. Welcome to Microsoft Q&A. You could set SourceItems and SelectedInteger to Dependency Property. And update MainWindow.vb as follows. MainWindow.xaml.vb:
Imports System.ComponentModel
Public Class MainWindow
Implements INotifyPropertyChanged
Public Sub New()
InitializeComponent()
DataContext = Me
End Sub
Public ReadOnly Property MyList As List(Of Integer)
Get
Return New List(Of Integer) From {1, 2, 3, 4, 5}
End Get
End Property
Private _myInteger As Integer
Public Property MyInteger As Integer
Get
Return _myInteger
End Get
Set(value As Integer)
If _myInteger <> value Then
_myInteger = value
OnPropertyChanged("MyInteger") ' Notify the UI that the property value has changed
End If
End Set
End Property
Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
Protected Sub OnPropertyChanged(propertyName As String)
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propertyName))
End Sub
End Class
CustomComboBox.vb:
Public Class CustomComboBox
Inherits Control
Public Shared ReadOnly SourceItemsProperty As DependencyProperty = DependencyProperty.Register("SourceItems", GetType(List(Of Integer)), GetType(CustomComboBox), New PropertyMetadata(Nothing))
Public Property SourceItems As List(Of Integer)
Get
Return CType(GetValue(SourceItemsProperty), List(Of Integer))
End Get
Set(value As List(Of Integer))
SetValue(SourceItemsProperty, value)
End Set
End Property
Public Shared ReadOnly SelectedIntegerProperty As DependencyProperty = DependencyProperty.Register("SelectedInteger", GetType(Integer), GetType(CustomComboBox), New PropertyMetadata(0))
Public Property SelectedInteger As Integer
Get
Return CInt(GetValue(SelectedIntegerProperty))
End Get
Set(value As Integer)
SetValue(SelectedIntegerProperty, value)
End Set
End Property
Shared Sub New()
DefaultStyleKeyProperty.OverrideMetadata(GetType(CustomComboBox), New FrameworkPropertyMetadata(GetType(CustomComboBox)))
End Sub
End Class
If you still have questions, please feel free to let me know. The problem will be better solved if more details are described (steps, screenshots of error messages, and code to reproduce the problem).
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
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.