' Follow steps 1a or 1b and then 2 to use this custom control in a XAML file. ' ' Step 1a) Using this custom control in a XAML file that exists in the current project. ' Add this XmlNamespace attribute to the root element of the markup file where it is ' to be used: ' ' xmlns:MyNamespace="clr-namespace:EgwWPFBaseLib" ' ' ' Step 1b) Using this custom control in a XAML file that exists in a different project. ' Add this XmlNamespace attribute to the root element of the markup file where it is ' to be used: ' ' xmlns:MyNamespace="clr-namespace:EgwWPFBaseLib;assembly=EgwWPFBaseLib" ' ' You will also need to add a project reference from the project where the XAML file lives ' to this project and Rebuild to avoid compilation errors: ' ' Right click on the target project in the Solution Explorer and ' "Add Reference"->"Projects"->[Browse to and select this project] ' ' ' Step 2) ' Go ahead and use your control in the XAML file. Note that Intellisense in the ' XML editor does not currently work on custom controls and its child elements. ' ' ' Imports System.Windows.Controls.Primitives Public Class EgwDropdownButton Inherits EgwToggleButton Public Enum PopupPlacementType BottomLeft BottomCenter BottomRight TopLeft TopCenter TopRight LeftTop LeftCenter LeftBottom RightTop RightCenter RightBottom End Enum Public Property DropDownContent As Object Get Return GetValue(DropDownContentProperty) End Get Set(value As Object) SetValue(DropDownContentProperty, value) End Set End Property Public Shared ReadOnly DropDownContentProperty As DependencyProperty = DependencyProperty.Register("DropDownContent", GetType(Object), GetType(EgwDropdownButton), New PropertyMetadata(Nothing)) ' --- Placement del popup --- Public Property PopupPlacement As PopupPlacementType Get Return CType(GetValue(PopupPlacementProperty), PopupPlacementType) End Get Set(value As PopupPlacementType) SetValue(PopupPlacementProperty, value) End Set End Property Public Shared ReadOnly PopupPlacementProperty As DependencyProperty = DependencyProperty.Register("PopupPlacement", GetType(PopupPlacementType), GetType(EgwDropdownButton), New PropertyMetadata(PopupPlacementType.BottomLeft)) Shared Sub New() 'This OverrideMetadata call tells the system that this element wants to provide a style that is different than its base class. 'This style is defined in themes\generic.xaml DefaultStyleKeyProperty.OverrideMetadata(GetType(EgwDropdownButton), New FrameworkPropertyMetadata(GetType(EgwDropdownButton))) End Sub Public Overrides Sub OnApplyTemplate() MyBase.OnApplyTemplate() Dim popup = TryCast(GetTemplateChild("PART_Popup"), Popup) Dim root = TryCast(Me, FrameworkElement) If popup Is Nothing OrElse root Is Nothing Then Return ' PlacementTarget deve essere il controllo, non la freccia popup.PlacementTarget = root AddHandler popup.Opened, Sub() Dim child = popup.Child child.Measure(New Size(Double.PositiveInfinity, Double.PositiveInfinity)) Dim popupWidth = child.DesiredSize.Width Dim popupHeight = child.DesiredSize.Height Dim rootWidth = root.ActualWidth Dim rootHeight = root.ActualHeight popup.HorizontalOffset = 0 popup.VerticalOffset = 0 Select Case PopupPlacement ' --- BOTTOM --- Case PopupPlacementType.BottomLeft popup.Placement = PlacementMode.Bottom Case PopupPlacementType.BottomCenter popup.Placement = PlacementMode.Bottom popup.HorizontalOffset = (rootWidth - popupWidth) / 2 Case PopupPlacementType.BottomRight popup.Placement = PlacementMode.Bottom popup.HorizontalOffset = rootWidth - popupWidth ' --- TOP --- Case PopupPlacementType.TopLeft popup.Placement = PlacementMode.Top Case PopupPlacementType.TopCenter popup.Placement = PlacementMode.Top popup.HorizontalOffset = (rootWidth - popupWidth) / 2 Case PopupPlacementType.TopRight popup.Placement = PlacementMode.Top popup.HorizontalOffset = rootWidth - popupWidth ' --- LEFT --- Case PopupPlacementType.LeftTop popup.Placement = PlacementMode.Left Case PopupPlacementType.LeftCenter popup.Placement = PlacementMode.Left popup.VerticalOffset = (rootHeight - popupHeight) / 2 Case PopupPlacementType.LeftBottom popup.Placement = PlacementMode.Left popup.VerticalOffset = rootHeight - popupHeight ' --- RIGHT --- Case PopupPlacementType.RightTop popup.Placement = PlacementMode.Right Case PopupPlacementType.RightCenter popup.Placement = PlacementMode.Right popup.VerticalOffset = (rootHeight - popupHeight) / 2 Case PopupPlacementType.RightBottom popup.Placement = PlacementMode.Right popup.VerticalOffset = rootHeight - popupHeight End Select End Sub End Sub End Class