0b44f5a723
- piccole migliorie.
417 lines
19 KiB
VB.net
417 lines
19 KiB
VB.net
' 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:EgtCamTest1"
|
|
'
|
|
'
|
|
' 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:EgtCamTest1;assembly=EgtCamTest1"
|
|
'
|
|
' 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.
|
|
'
|
|
' <MyNamespace:EgtFloatingPanel/>
|
|
'
|
|
|
|
Imports System.Windows.Controls.Primitives
|
|
|
|
Namespace EgtFloating
|
|
|
|
<TemplatePart(Name:="PART_TitleBar", Type:=GetType(ContentControl))>
|
|
<TemplatePart(Name:="PART_ExtendButton", Type:=GetType(ToggleButton))>
|
|
<TemplatePart(Name:="PART_PanelPresenter", Type:=GetType(ItemsPresenter))>
|
|
<TemplatePart(Name:="PART_PopUpStackPanel", Type:=GetType(StackPanel))>
|
|
Public Class EgtFloatingPanel
|
|
Inherits System.Windows.Controls.ItemsControl
|
|
|
|
Private m_FloatingManager As EgtFloatingManager ' Riferimento al floating manager da cui è stato creato
|
|
Private m_FloatingTray As EgtFloatingTray
|
|
Private m_FloatingWindow As EgtFloatingWindow ' Riferimento alla floating window in cui si trova; sarà = nothing se il pannello si trova nel manager
|
|
|
|
Private m_bFirstLoaded As Boolean = True
|
|
Private m_bFromCode As Boolean = False
|
|
|
|
Public Shared ReadOnly CurrPanelStateProperty As DependencyProperty = DependencyProperty.Register("CurrPanelState", GetType(FloatingPanelState), GetType(EgtFloatingPanel), New PropertyMetadata(FloatingPanelState.DOCK_TOP))
|
|
Public Property CurrPanelState() As FloatingPanelState
|
|
Get
|
|
Return CType(GetValue(CurrPanelStateProperty), FloatingPanelState)
|
|
End Get
|
|
Set(ByVal value As FloatingPanelState)
|
|
SetValue(CurrPanelStateProperty, value)
|
|
End Set
|
|
End Property
|
|
Public Enum FloatingPanelState As Integer
|
|
DOCK_TOP
|
|
DOCK_BOTTOM
|
|
DOCK_LEFT
|
|
DOCK_RIGHT
|
|
FLOATING
|
|
End Enum
|
|
|
|
Public Shared ReadOnly IsFloatingProperty As DependencyProperty = DependencyProperty.Register("IsFloating", GetType(Boolean), GetType(EgtFloatingPanel), New PropertyMetadata(True))
|
|
''' <summary>
|
|
''' Property that say if panel is Top dockable
|
|
''' </summary>
|
|
Public Property IsFloating() As Boolean
|
|
Get
|
|
Return CBool(GetValue(IsFloatingProperty))
|
|
End Get
|
|
Set(ByVal value As Boolean)
|
|
SetValue(IsFloatingProperty, value)
|
|
End Set
|
|
End Property
|
|
|
|
Public Shared ReadOnly IsTopDockableProperty As DependencyProperty = DependencyProperty.Register("IsTopDockable", GetType(Boolean), GetType(EgtFloatingPanel), New PropertyMetadata(True))
|
|
''' <summary>
|
|
''' Property that say if panel is Top dockable
|
|
''' </summary>
|
|
Public Property IsTopDockable() As Boolean
|
|
Get
|
|
Return CBool(GetValue(IsTopDockableProperty))
|
|
End Get
|
|
Set(ByVal value As Boolean)
|
|
SetValue(IsTopDockableProperty, value)
|
|
End Set
|
|
End Property
|
|
|
|
Public Shared ReadOnly IsBottomDockableProperty As DependencyProperty = DependencyProperty.Register("IsBottomDockable", GetType(Boolean), GetType(EgtFloatingPanel), New PropertyMetadata(True))
|
|
''' <summary>
|
|
''' Property that say if panel is Bottom dockable
|
|
''' </summary>
|
|
Public Property IsBottomDockable() As Boolean
|
|
Get
|
|
Return CBool(GetValue(IsBottomDockableProperty))
|
|
End Get
|
|
Set(ByVal value As Boolean)
|
|
SetValue(IsBottomDockableProperty, value)
|
|
End Set
|
|
End Property
|
|
|
|
Public Shared ReadOnly IsLeftDockableProperty As DependencyProperty = DependencyProperty.Register("IsLeftDockable", GetType(Boolean), GetType(EgtFloatingPanel), New PropertyMetadata(True))
|
|
''' <summary>
|
|
''' Property that say if panel is Left dockable
|
|
''' </summary>
|
|
Public Property IsLeftDockable() As Boolean
|
|
Get
|
|
Return CBool(GetValue(IsLeftDockableProperty))
|
|
End Get
|
|
Set(ByVal value As Boolean)
|
|
SetValue(IsLeftDockableProperty, value)
|
|
End Set
|
|
End Property
|
|
|
|
Public Shared ReadOnly IsRightDockableProperty As DependencyProperty = DependencyProperty.Register("IsRightDockable", GetType(Boolean), GetType(EgtFloatingPanel), New PropertyMetadata(True))
|
|
''' <summary>
|
|
''' Property that say if panel is Right dockable
|
|
''' </summary>
|
|
Public Property IsRightDockable() As Boolean
|
|
Get
|
|
Return CBool(GetValue(IsRightDockableProperty))
|
|
End Get
|
|
Set(ByVal value As Boolean)
|
|
SetValue(IsRightDockableProperty, value)
|
|
End Set
|
|
End Property
|
|
|
|
' Proprietà che permette di impostare l'altezza della TitleBar
|
|
Public Shared ReadOnly TitleBarHeightProperty As DependencyProperty = DependencyProperty.Register("TitleBarHeight", GetType(Double), GetType(EgtFloatingPanel), New PropertyMetadata(10.0))
|
|
Public Property TitleBarHeight() As Double
|
|
Get
|
|
Return CType(GetValue(TitleBarHeightProperty), Double)
|
|
End Get
|
|
Set(ByVal value As Double)
|
|
SetValue(TitleBarHeightProperty, value)
|
|
End Set
|
|
End Property
|
|
|
|
' Proprietà che permette di impostare l'orientamento della finestra per posizionare la TitleBar
|
|
Public Shared ReadOnly TitleBarOrientationProperty As DependencyProperty = DependencyProperty.Register("TitleBarOrientation", GetType(System.Windows.Controls.Orientation), GetType(EgtFloatingPanel), New PropertyMetadata(System.Windows.Controls.Orientation.Vertical))
|
|
Public Property TitleBarOrientation() As System.Windows.Controls.Orientation
|
|
Get
|
|
Return CType(GetValue(TitleBarOrientationProperty), System.Windows.Controls.Orientation)
|
|
End Get
|
|
Set(ByVal value As System.Windows.Controls.Orientation)
|
|
SetValue(TitleBarOrientationProperty, value)
|
|
End Set
|
|
End Property
|
|
|
|
' Proprietà che permette di aprire il PopUp sul click dell'apposito tasto
|
|
Public Shared ReadOnly PopUpIsOpenProperty As DependencyProperty = DependencyProperty.Register("PopUpIsOpen", GetType(Boolean), GetType(EgtFloatingPanel), New PropertyMetadata(False))
|
|
Public Property PopUpIsOpen() As Boolean
|
|
Get
|
|
Return CBool(GetValue(PopUpIsOpenProperty))
|
|
End Get
|
|
Set(ByVal value As Boolean)
|
|
SetValue(PopUpIsOpenProperty, value)
|
|
End Set
|
|
End Property
|
|
|
|
' Proprietà che definisce se è una toolbar(elenco di elementi)(setta uno StackPanel come contenitore) o uno UserControl più complesso(setta una Grid ad una sola cella come contenitore)
|
|
Public Shared ReadOnly IsToolBarProperty As DependencyProperty = DependencyProperty.Register("IsToolBar", GetType(Boolean), GetType(EgtFloatingPanel), New PropertyMetadata(True))
|
|
Public Property IsToolBar() As Boolean
|
|
Get
|
|
Return CBool(GetValue(IsToolBarProperty))
|
|
End Get
|
|
Set(ByVal value As Boolean)
|
|
SetValue(IsToolBarProperty, value)
|
|
End Set
|
|
End Property
|
|
|
|
'Attached property che permette di aprire aggiungere contenuti all'ItemPresenter del PopUp
|
|
Public Shared ReadOnly IsInPopUpProperty As DependencyProperty = DependencyProperty.RegisterAttached("IsInPopUp", GetType(Boolean), GetType(EgtFloatingPanel), New PropertyMetadata(False))
|
|
Public Shared Function GetIsInPopUp(element As UIElement) As Boolean
|
|
Return CBool(element.GetValue(IsInPopUpProperty))
|
|
End Function
|
|
Public Shared Sub SetIsInPopUp(element As UIElement, ByVal value As Boolean)
|
|
element.SetValue(IsInPopUpProperty, value)
|
|
End Sub
|
|
|
|
Private m_thmb_Header As ContentControl
|
|
Public ReadOnly Property thmb_Header As ContentControl
|
|
Get
|
|
Return m_thmb_Header
|
|
End Get
|
|
End Property
|
|
|
|
Private m_btn_Extender As ToggleButton
|
|
Public ReadOnly Property btn_Extender As ToggleButton
|
|
Get
|
|
Return m_btn_Extender
|
|
End Get
|
|
End Property
|
|
|
|
Private m_PopUpStackPanel As StackPanel
|
|
Public ReadOnly Property PopUpStackPanel As StackPanel
|
|
Get
|
|
Return m_PopUpStackPanel
|
|
End Get
|
|
End Property
|
|
|
|
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(EgtFloatingPanel), New FrameworkPropertyMetadata(GetType(EgtFloatingPanel)))
|
|
End Sub
|
|
|
|
Public Overrides Sub OnApplyTemplate()
|
|
MyBase.OnApplyTemplate()
|
|
' Retrieve the ContentControl Header from the current template
|
|
m_thmb_Header = TryCast(MyBase.GetTemplateChild("PART_TitleBar"), ContentControl)
|
|
' Retrieve the Extend Button from the current template
|
|
m_btn_Extender = TryCast(MyBase.GetTemplateChild("PART_ExtendButton"), ToggleButton)
|
|
' Retrieve the PopUp's StackPanel from the current template
|
|
m_PopUpStackPanel = TryCast(MyBase.GetTemplateChild("PART_PopUpStackPanel"), StackPanel)
|
|
' Hook up the event handler
|
|
If m_thmb_Header IsNot Nothing Then
|
|
AddHandler m_thmb_Header.MouseDown, AddressOf m_thmb_Header_PreviewMouseDown
|
|
AddHandler m_thmb_Header.MouseUp, AddressOf m_thmb_Header_PreviewMouseUp
|
|
End If
|
|
If m_PopUpStackPanel IsNot Nothing Then
|
|
AddHandler m_PopUpStackPanel.PreviewMouseUp, AddressOf m_PopUpStackPanel_MouseUp
|
|
End If
|
|
Dim Index As Integer = 0
|
|
' Cerco tra gli item del panel quelli con AttachedProperty che indica che devono stare nel popup del Floating Panel e li sposto lì
|
|
While Index <= Me.Items.Count - 1
|
|
Dim CurrControl As FrameworkElement = TryCast(Me.Items(Index), FrameworkElement)
|
|
Dim PopUpProperty As Boolean = DirectCast(CurrControl.GetValue(EgtFloatingPanel.IsInPopUpProperty), Boolean)
|
|
If PopUpProperty = True Then
|
|
Me.Items.Remove(CurrControl)
|
|
m_PopUpStackPanel.Children.Add(CurrControl)
|
|
Else
|
|
Index += 1
|
|
End If
|
|
End While
|
|
' Se non c'è nessun elemento che va nel popup, nascondo il bottone che lo apre
|
|
If m_PopUpStackPanel.Children.Count = 0 Then
|
|
m_btn_Extender.Visibility = Windows.Visibility.Collapsed
|
|
End If
|
|
End Sub
|
|
|
|
Public Sub Me_Initialized(sender As Object, e As System.EventArgs) Handles Me.Initialized
|
|
If Not m_bFromCode AndAlso m_bFirstLoaded Then
|
|
m_FloatingTray = Utility.FindAncestor(Of EgtFloatingTray)(Me)
|
|
If Not IsNothing(m_FloatingTray) Then
|
|
Select Case DirectCast(m_FloatingTray.GetValue(DockPanel.DockProperty), Dock)
|
|
Case Dock.Top
|
|
CurrPanelState = FloatingPanelState.DOCK_TOP
|
|
Case Dock.Bottom
|
|
CurrPanelState = FloatingPanelState.DOCK_BOTTOM
|
|
Case Dock.Left
|
|
CurrPanelState = FloatingPanelState.DOCK_LEFT
|
|
Case Dock.Right
|
|
CurrPanelState = FloatingPanelState.DOCK_RIGHT
|
|
End Select
|
|
Else
|
|
m_FloatingWindow = Utility.FindAncestor(Of EgtFloatingWindow)(Me)
|
|
CurrPanelState = FloatingPanelState.FLOATING
|
|
If IsNothing(m_FloatingWindow) Then
|
|
End If
|
|
End If
|
|
m_FloatingManager = Utility.FindAncestor(Of EgtFloatingManager)(Me)
|
|
m_bFirstLoaded = False
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub Me_Loaded(sender As Object, e As System.Windows.RoutedEventArgs) Handles Me.Loaded
|
|
If Not IsNothing(m_FloatingTray) Then
|
|
'm_FloatingTray.Measure(New Size(Double.PositiveInfinity, Double.PositiveInfinity))
|
|
If CurrPanelState = FloatingPanelState.DOCK_TOP Or CurrPanelState = FloatingPanelState.DOCK_BOTTOM Then
|
|
Me.MaxWidth = m_FloatingTray.ActualWidth
|
|
ElseIf CurrPanelState = FloatingPanelState.DOCK_LEFT Or CurrPanelState = FloatingPanelState.DOCK_RIGHT Then
|
|
Me.MaxHeight = m_FloatingTray.ActualHeight
|
|
End If
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub m_PopUpStackPanel_MouseUp(sender As Object, e As MouseEventArgs)
|
|
PopUpIsOpen = False
|
|
End Sub
|
|
|
|
Private Sub m_thmb_Header_PreviewMouseDown(sender As Object, e As MouseEventArgs)
|
|
If IsFloating Then
|
|
Dim pos As Point = Me.PointToScreen(New Point(0, 0))
|
|
ChangePosition(pos)
|
|
For Each Tray In m_FloatingManager.Items
|
|
If Not TypeOf Tray Is EgtFloatingTray Then Continue For
|
|
Dim CurrTray As EgtFloatingTray = DirectCast(Tray, EgtFloatingTray)
|
|
CurrTray.ShowTrayWindow()
|
|
Next
|
|
m_FloatingWindow.IsClicked = True
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub m_thmb_Header_PreviewMouseUp(sender As Object, e As MouseButtonEventArgs)
|
|
If IsFloating Then
|
|
If m_FloatingWindow.IsOnWindow Then
|
|
ChangePosition(m_FloatingWindow.TrayMouseOver)
|
|
Else
|
|
For Each Tray In m_FloatingManager.Items
|
|
If Not TypeOf Tray Is EgtFloatingTray Then Continue For
|
|
Dim CurrTray As EgtFloatingTray = DirectCast(Tray, EgtFloatingTray)
|
|
CurrTray.HideTrayWindow()
|
|
Next
|
|
End If
|
|
For Each FloatingTray In m_FloatingManager.Items
|
|
If Not TypeOf FloatingTray Is EgtFloatingTray Then Continue For
|
|
Dim CurrTray As EgtFloatingTray = DirectCast(FloatingTray, EgtFloatingTray)
|
|
CurrTray.HideTrayWindow()
|
|
Next
|
|
m_FloatingManager.ParentWindow.Focus()
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub RemoveFromWindow()
|
|
'm_FloatingWindow.MyContentPresenter.Content = Nothing
|
|
m_FloatingWindow.Content = Nothing
|
|
End Sub
|
|
|
|
Private Sub AddToTray(Tray As EgtFloatingTray)
|
|
Tray.Items.Add(Me)
|
|
m_FloatingTray = Tray
|
|
End Sub
|
|
|
|
Private Sub InitializeEgtFloatingWindow(Owner As Window, pos As Point)
|
|
m_FloatingWindow = New EgtFloatingWindow(m_FloatingManager, Me) With {
|
|
.Content = Me,
|
|
.Height = Me.ActualHeight,
|
|
.Width = Me.ActualWidth,
|
|
.Top = pos.Y,
|
|
.Left = pos.X,
|
|
.Topmost = True,
|
|
.Owner = Owner
|
|
}
|
|
m_FloatingManager.EgtFloatingWindowList.Add(m_FloatingWindow)
|
|
End Sub
|
|
|
|
Public Sub InitializeEgtFloatingPanelWithWindow(FloatingManager As EgtFloatingManager, pos As Point)
|
|
m_bFromCode = True
|
|
m_FloatingManager = FloatingManager
|
|
' Creo nuova finestra e vi assegno come contenuto il pannello
|
|
InitializeEgtFloatingWindow(m_FloatingManager.ParentWindow, pos)
|
|
Me.CurrPanelState = FloatingPanelState.FLOATING
|
|
m_FloatingWindow.Show()
|
|
End Sub
|
|
|
|
Public Sub InitializeEgtFloatingPanelWithTray(FloatingManager As EgtFloatingManager, Tray As EgtFloatingTray)
|
|
m_bFromCode = True
|
|
m_FloatingManager = FloatingManager
|
|
AddToTray(Tray)
|
|
Dim CurrTrayDock As Dock = DirectCast(Tray.GetValue(DockPanel.DockProperty), Dock)
|
|
Select Case DirectCast(Tray.GetValue(DockPanel.DockProperty), Dock)
|
|
Case Dock.Top
|
|
CurrPanelState = FloatingPanelState.DOCK_TOP
|
|
Case Dock.Bottom
|
|
CurrPanelState = FloatingPanelState.DOCK_BOTTOM
|
|
Case Dock.Left
|
|
CurrPanelState = FloatingPanelState.DOCK_LEFT
|
|
Case Dock.Right
|
|
CurrPanelState = FloatingPanelState.DOCK_RIGHT
|
|
End Select
|
|
End Sub
|
|
|
|
Public Overloads Sub ChangePosition(pos As Point)
|
|
Select Case CurrPanelState
|
|
Case FloatingPanelState.FLOATING
|
|
m_FloatingWindow.Top = pos.Y
|
|
m_FloatingWindow.Left = pos.X
|
|
Case Else
|
|
m_FloatingTray.Items.Remove(Me)
|
|
' Creo nuova finestra e vi assegno come contenuto il pannello
|
|
InitializeEgtFloatingWindow(m_FloatingManager.ParentWindow, pos)
|
|
Me.CurrPanelState = FloatingPanelState.FLOATING
|
|
m_FloatingWindow.Show()
|
|
End Select
|
|
End Sub
|
|
|
|
Public Overloads Sub ChangePosition(Tray As EgtFloatingTray)
|
|
Select Case CurrPanelState
|
|
Case FloatingPanelState.FLOATING
|
|
RemoveFromWindow()
|
|
AddToTray(Tray)
|
|
m_FloatingWindow.Close()
|
|
Dim CurrTrayDock As Dock = DirectCast(m_FloatingWindow.TrayMouseOver.GetValue(DockPanel.DockProperty), Dock)
|
|
Select Case CurrTrayDock
|
|
Case Dock.Top
|
|
CurrPanelState = FloatingPanelState.DOCK_TOP
|
|
Case Dock.Bottom
|
|
CurrPanelState = FloatingPanelState.DOCK_BOTTOM
|
|
Case Dock.Left
|
|
CurrPanelState = FloatingPanelState.DOCK_LEFT
|
|
Case Dock.Right
|
|
CurrPanelState = FloatingPanelState.DOCK_RIGHT
|
|
End Select
|
|
Case Else
|
|
m_FloatingTray.Items.Remove(Me)
|
|
AddToTray(Tray)
|
|
Dim CurrTrayDock As Dock = DirectCast(Tray.GetValue(DockPanel.DockProperty), Dock)
|
|
Select Case CurrTrayDock
|
|
Case Dock.Top
|
|
CurrPanelState = FloatingPanelState.DOCK_TOP
|
|
Case Dock.Bottom
|
|
CurrPanelState = FloatingPanelState.DOCK_BOTTOM
|
|
Case Dock.Left
|
|
CurrPanelState = FloatingPanelState.DOCK_LEFT
|
|
Case Dock.Right
|
|
CurrPanelState = FloatingPanelState.DOCK_RIGHT
|
|
End Select
|
|
|
|
End Select
|
|
End Sub
|
|
|
|
End Class
|
|
|
|
End Namespace |