ae5a2467da
- Modificata behaviour che apre e chiude gli expander automaticamente. - Modificato calcolo dell'altezza massima dei parametri operazione di lavorazione. - Migliorie varie.
181 lines
8.5 KiB
VB.net
181 lines
8.5 KiB
VB.net
'----------------------------------------------------------------------------
|
|
' EgalTech 2016-2016
|
|
'----------------------------------------------------------------------------
|
|
' File : AutomaticCloseExpander.vb Data : 8.9.16 Versione : 1
|
|
' Content : AutomatiCloseExpander Behavior (see detailed description below)
|
|
'
|
|
' Created by : Emmanuele Sassi
|
|
' Edited by :
|
|
'
|
|
' Changes :
|
|
'
|
|
'----------------------------------------------------------------------------
|
|
'
|
|
' Behavior description: permit to close other Expander when one is about to expand if they have to use more space than how many the StackPanel offers.
|
|
' Control that can use this behavior: StackPanel
|
|
' Internal structure of the control that can use it (example):
|
|
'
|
|
' <StackPanel>
|
|
' <Expander Header="Expander"/>
|
|
' <Expander Header="Expander"/>
|
|
' <Button Height="30" Width="30"/>
|
|
' <Expander Header="Expander">
|
|
' </Expander>
|
|
' <Interactivity:Interaction.Behaviors>
|
|
' <local:AutomaticCloseExpander/>
|
|
' </Interactivity:Interaction.Behaviors>
|
|
' </StackPanel>
|
|
'
|
|
' IMPORTANT: The behavior have to be added at the end of the StackPanel to function correctly
|
|
' Needed library: System.Windows.Interactivity
|
|
|
|
Imports System.Windows.Interactivity
|
|
|
|
Public Class AutomaticCloseExpander
|
|
Inherits Behavior(Of StackPanel)
|
|
|
|
Private ExpanderList As New List(Of Expander)
|
|
Private OtherControlList As New List(Of FrameworkElement)
|
|
|
|
Protected Overrides Sub OnAttached()
|
|
MyBase.OnAttached()
|
|
For Each StackPanelChildren In Me.AssociatedObject.Children
|
|
If TypeOf StackPanelChildren Is Expander Then
|
|
Dim CurrExpander As Expander = DirectCast(StackPanelChildren, Expander)
|
|
ExpanderList.Add(CurrExpander)
|
|
AddHandler CurrExpander.Expanded, AddressOf Expander_Expanded
|
|
Else
|
|
Dim OtherControl As FrameworkElement = DirectCast(StackPanelChildren, FrameworkElement)
|
|
OtherControlList.Add(OtherControl)
|
|
End If
|
|
Next
|
|
End Sub
|
|
|
|
Private Sub Expander_Expanded(sender As Object, e As System.Windows.RoutedEventArgs)
|
|
Dim SelectedExpander As Expander = DirectCast(sender, Expander)
|
|
If Me.AssociatedObject.Orientation = Orientation.Vertical Then
|
|
VerticalVerifyDimension(SelectedExpander)
|
|
Else
|
|
HorizontalVerifyDimension(SelectedExpander)
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub VerticalVerifyDimension(SelectedExpander As Expander)
|
|
Dim AssociatedObjectElement As FrameworkElement = DirectCast(AssociatedObject, FrameworkElement)
|
|
AssociatedObjectElement.Measure(New Size(Double.PositiveInfinity, Double.PositiveInfinity))
|
|
Dim TotalCurrentHeight = AssociatedObjectElement.DesiredSize.Height
|
|
' Aggiungo la dimensione del contenuto dell'expander selezionato
|
|
Dim SelectedContent As FrameworkElement = DirectCast(SelectedExpander.Content, FrameworkElement)
|
|
SelectedContent.Measure(New Size(Double.PositiveInfinity, Double.PositiveInfinity))
|
|
TotalCurrentHeight += SelectedContent.DesiredSize.Height
|
|
' Aggiungo il padding del contenuto
|
|
TotalCurrentHeight += (SelectedExpander.Padding.Top + SelectedExpander.Padding.Bottom)
|
|
If TotalCurrentHeight < Me.AssociatedObject.MaxHeight Then
|
|
Return
|
|
End If
|
|
For Index = ExpanderList.Count - 1 To 0 Step -1
|
|
If TotalCurrentHeight > Me.AssociatedObject.MaxHeight Then
|
|
If ExpanderList(Index) IsNot SelectedExpander AndAlso ExpanderList(Index).IsExpanded = True Then
|
|
'TotalCurrentHeight -= ExpanderList(Index).ActualHeight
|
|
ExpanderList(Index).IsExpanded = False
|
|
Dim CurrExpanderContent As FrameworkElement = DirectCast(ExpanderList(Index).Content, FrameworkElement)
|
|
CurrExpanderContent.Measure(New Size(Double.PositiveInfinity, Double.PositiveInfinity))
|
|
TotalCurrentHeight -= CurrExpanderContent.DesiredSize.Height
|
|
' Sottraggo anche i padding
|
|
TotalCurrentHeight -= (ExpanderList(Index).Padding.Top + ExpanderList(Index).Padding.Bottom)
|
|
End If
|
|
Else
|
|
Exit For
|
|
End If
|
|
Next
|
|
|
|
|
|
'Dim TotalDimension As Double = 0
|
|
''Aggiungo la dimensione di tutti gli Header
|
|
'For Each Expander In ExpanderList
|
|
' If Expander IsNot SelectedExpander Then
|
|
' If Not Expander.IsExpanded Then
|
|
' TotalDimension += Expander.ActualHeight
|
|
' Else
|
|
' Dim ExpanderContent As FrameworkElement = DirectCast(Expander.Content, FrameworkElement)
|
|
' ExpanderContent.Measure(New Size(Double.PositiveInfinity, Double.PositiveInfinity))
|
|
' TotalDimension += (Expander.ActualHeight - ExpanderContent.DesiredSize.Height)
|
|
' End If
|
|
' Else
|
|
' TotalDimension += Expander.ActualHeight
|
|
' End If
|
|
'Next
|
|
'' Aggiungo la dimensione dei controlli fissi (non Expander)
|
|
'For Each OtherControl In OtherControlList
|
|
' TotalDimension += OtherControl.ActualHeight
|
|
'Next
|
|
'' Aggiungo la dimensione del contenuto dell'expander selezionato
|
|
'Dim SelectedContent As FrameworkElement = DirectCast(SelectedExpander.Content, FrameworkElement)
|
|
'SelectedContent.Measure(New Size(Double.PositiveInfinity, Double.PositiveInfinity))
|
|
'TotalDimension += SelectedContent.DesiredSize.Height
|
|
'' Verifico per tutti gli expander (tranne quello selezionato) a partire dal primo se sono espansi e nel caso se la loro dimensione totale li fa stare nello spazio disponibile
|
|
'Dim Index As Integer = 0
|
|
'For Index = 0 To ExpanderList.Count - 1
|
|
' If ExpanderList(Index) IsNot SelectedExpander Then
|
|
' If ExpanderList(Index).IsExpanded Then
|
|
' Dim ExpanderContent As FrameworkElement = DirectCast(ExpanderList(Index).Content, FrameworkElement)
|
|
' TotalDimension += ExpanderContent.ActualHeight
|
|
' If TotalDimension > Me.AssociatedObject.MaxHeight Then
|
|
' Exit For
|
|
' End If
|
|
' End If
|
|
' End If
|
|
'Next
|
|
'For CancelIndex = Index To ExpanderList.Count - 1
|
|
' If ExpanderList(CancelIndex) IsNot SelectedExpander Then
|
|
' ExpanderList(CancelIndex).IsExpanded = False
|
|
' End If
|
|
'Next
|
|
End Sub
|
|
|
|
Private Sub HorizontalVerifyDimension(SelectedExpander As Expander)
|
|
Dim TotalDimension As Double = 0
|
|
'Aggiungo la dimensione di tutti gli Header
|
|
For Each Expander In ExpanderList
|
|
If Expander IsNot SelectedExpander Then
|
|
If Not Expander.IsExpanded Then
|
|
TotalDimension += Expander.ActualWidth
|
|
Else
|
|
Dim ExpanderContent As FrameworkElement = DirectCast(Expander.Content, FrameworkElement)
|
|
ExpanderContent.Measure(New Size(Double.PositiveInfinity, Double.PositiveInfinity))
|
|
TotalDimension += (Expander.ActualWidth - ExpanderContent.DesiredSize.Width)
|
|
End If
|
|
Else
|
|
TotalDimension += Expander.ActualWidth
|
|
End If
|
|
Next
|
|
' Aggiungo la dimensione dei controlli fissi (non Expander)
|
|
For Each OtherControl In OtherControlList
|
|
TotalDimension += OtherControl.ActualWidth
|
|
Next
|
|
' Aggiungo la dimensione del contenuto dell'expander selezionato
|
|
Dim SelectedContent As FrameworkElement = DirectCast(SelectedExpander.Content, FrameworkElement)
|
|
SelectedContent.Measure(New Size(Double.PositiveInfinity, Double.PositiveInfinity))
|
|
TotalDimension += SelectedContent.DesiredSize.Width
|
|
' Verifico per tutti gli expander (tranne quello selezionato) a partire dal primo se sono espansi e nel caso se la loro dimensione totale li fa stare nello spazio disponibile
|
|
Dim Index As Integer = 0
|
|
For Index = 0 To ExpanderList.Count - 1
|
|
If ExpanderList(Index) IsNot SelectedExpander Then
|
|
If ExpanderList(Index).IsExpanded Then
|
|
Dim ExpanderContent As FrameworkElement = DirectCast(ExpanderList(Index).Content, FrameworkElement)
|
|
TotalDimension += ExpanderContent.ActualWidth
|
|
If TotalDimension > Me.AssociatedObject.ActualWidth Then
|
|
Exit For
|
|
End If
|
|
End If
|
|
End If
|
|
Next
|
|
For CancelIndex = Index To ExpanderList.Count - 1
|
|
If ExpanderList(CancelIndex) IsNot SelectedExpander Then
|
|
ExpanderList(CancelIndex).IsExpanded = False
|
|
End If
|
|
Next
|
|
End Sub
|
|
|
|
End Class
|