类型一 : 自定义控件包含多个基本控件 ,此时用vs自动生成的控件,包含XAML文件和.C#或者.VB的后台文件,继承的类为Control
类型二:自定义控件是一个基本控件演变而来,具有基本控件的大部分特征,这时候只需要建立后台文件即可,没有XAML文件,继承的类也为基本的控件类,如ComBobox
简单例子
Public Class myCombobox
Inherits TextBox
'Public Property ListColor() As String
' Get
' Return DirectCast(GetValue(_ListColor), String)
' End Get
' Set(value As String)
' SetValue(_ListColor, value)
' End Set
'End Property
'Public Shared ReadOnly _ListColor As DependencyProperty = DependencyProperty.Register("_ListColor", GetType(List(Of MODEL .clsvwColorMaster ), GetType(myCombobox ), New PropertyMetadata(Nothing))
Public obs As List(Of MODEL.clsvwColorMaster)
Sub New()
obs = BLL.BL_clsvwColorMaster.FillData(, , , 2)
Dim objBding As New Binding
objBding.Source = obs(0)
objBding.Path = New PropertyPath("ColorCode")
objBding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
objBding.Mode = BindingMode.TwoWay
Me.SetBinding(TextBox.TextProperty, objBding)
'BindingOperations.SetBinding(Me, ComboBox.ItemsSourceProperty, objBding)
'Me.SetBinding(ComboBox.ItemsSourceProperty, objBding)
End Sub
End Class