Files
EgtWPFLib5/EgtFloating/EgtFloatingPanel.vb
Renzo Lanza 9a213bb350 EgtWPFLib5 2.2j2 :
- rimossa Proprietà IsFloating di EgtFloatingPanel e tutte le funzioni/sub ad essa collegate. 
- rimossa EgtFloatingWindow e tutti i suoi riferimenti e funzioni/sub ad essa collegate. 
- ripristinato Me_DimensionChanged() nel Me_Loaded() di EgtFloatingTray.
2020-10-12 09:53:00 +00:00

287 lines
13 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_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 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)
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
CurrPanelState = FloatingPanelState.FLOATING
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 AddToTray(Tray As EgtFloatingTray)
Tray.Items.Add(Me)
m_FloatingTray = Tray
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
End Class
End Namespace