Files
EgtCAM5/OptionPanel/MachiningOptionPanel/OperationExpander/OperationExpanderV.xaml.vb
T
Dario Sassi 70aff691c0 EgtCAM5 :
- aggiunta gestione utensili e lavorazione WaterJet
- ancora alcune correzioni per selezione multipla lavorazioni.
2019-07-10 13:10:59 +00:00

154 lines
7.4 KiB
VB.net

Imports EgtWPFLib5
Imports EgtWPFLib5.EgtFloating
Public Class OperationExpanderV
Private m_OperationExpanderVM As OperationExpanderVM
Private EgtFloatingTray As EgtFloatingTray
Private OptionPanelView As UserControl
Private OptionPanelViewStackPanel As StackPanel
'Private OperationParameters As ContentPresenter
Private MachiningTreeContentPresenter As ContentPresenter
Private MachiningTreeUserControl As UserControl
Private MachiningTreeExpander As Expander
Private SimulationContentPresenter As ContentPresenter
Private SimulationUserControl As UserControl
Private SimulationExpanderStackPanel As StackPanel
Private SimulationExpander As Expander
Private GenerateButton As Button
Private m_bFirst As Boolean = True
#Region "CONSTRUCTOR"
Sub New()
' Funzione che interpreta l'xaml
InitializeComponent()
' Assegno al riferimento locale al VM il VM preso dal DataContext
m_OperationExpanderVM = DirectCast(Me.DataContext, OperationExpanderVM)
End Sub
#End Region ' CONSTRUCTOR
#Region "EVENTS"
Private Sub MachiningOpListBoxItem_LostKeyboardFocus(sender As Object, e As KeyboardFocusChangedEventArgs)
Dim TextBox As TextBox = TryCast(sender, TextBox)
If IsNothing(TextBox) Then Return
Dim SelOp As MachiningOpListBoxItem = TryCast(TextBox.DataContext, MachiningOpListBoxItem)
If IsNothing(SelOp) Then Return
If MachiningOpListBoxItem.m_CloseModifyLostFocus Then
SelOp.ModifyNameEsc()
Else
If MachiningOpListBoxItem.m_Spy Then
MachiningOpListBoxItem.m_CloseModifyLostFocus = True
MachiningOpListBoxItem.m_Spy = False
End If
Keyboard.Focus(TextBox)
End If
End Sub
Private Sub MachiningOpListBoxItem_IsVisibleChanged(sender As Object, e As DependencyPropertyChangedEventArgs)
Dim bNewVal As Boolean = false
Try
bNewVal = CType( e.NewValue, Boolean)
Catch
End Try
If bNewVal Then
Dim inElem As IInputElement = TryCast( sender, IInputElement)
If Not IsNothing( inElem) Then Keyboard.Focus(inElem)
End If
End Sub
#End Region ' EVENTS
Private Sub OperationExpanderView_Loaded(sender As Object, e As System.Windows.RoutedEventArgs) Handles Me.Loaded
If m_bFirst Then
EgtFloatingTray = FindAncestor(Of EgtFloatingTray)(Me)
OptionPanelView = FindAncestor(Of UserControl)(Me)
OptionPanelViewStackPanel = DirectCast(OptionPanelView.Content, StackPanel)
MachiningTreeContentPresenter = DirectCast(OptionPanelViewStackPanel.Children(1), ContentPresenter)
MachiningTreeUserControl = DirectCast(MachiningTreeContentPresenter.Content, UserControl)
MachiningTreeExpander = DirectCast(MachiningTreeUserControl.Content, Expander)
SimulationContentPresenter = DirectCast(OptionPanelViewStackPanel.Children(2), ContentPresenter)
SimulationUserControl = DirectCast(SimulationContentPresenter.Content, UserControl)
SimulationExpanderStackPanel = DirectCast(SimulationUserControl.Content, StackPanel)
SimulationExpander = DirectCast(SimulationExpanderStackPanel.Children(0), Expander)
GenerateButton = DirectCast(SimulationExpanderStackPanel.Children(2), Button)
' Gestisco l'evento SizeChanged della Tray
AddHandler EgtFloatingTray.SizeChanged, AddressOf OperationExpanderTray_SizeChanged
m_bFirst = False
End If
CalculateOperationParametersStackPanelMaxHeight()
End Sub
Private Sub OperationExpanderTray_SizeChanged(sender As Object, e As System.Windows.SizeChangedEventArgs)
CalculateOperationParametersStackPanelMaxHeight()
'For Each Expander In OperationParametersStackPanel.Children
' If TypeOf Expander Is Expander Then
' Dim CurrExpander As Expander = DirectCast(Expander, Expander)
' CurrExpander.IsExpanded = False
' End If
'Next
End Sub
Private Sub CalculateOperationParametersStackPanelMaxHeight()
Dim OccupiedHeight As Double = 0
If Not MachiningTreeExpander.IsExpanded Then
OccupiedHeight += MachiningTreeExpander.ActualHeight
Else
Dim MachiningTreeExpanderContent As FrameworkElement = DirectCast(MachiningTreeExpander.Content, FrameworkElement)
MachiningTreeExpanderContent.Measure(New Size(Double.PositiveInfinity, Double.PositiveInfinity))
OccupiedHeight += (MachiningTreeExpander.ActualHeight - MachiningTreeExpanderContent.DesiredSize.Height)
End If
If Not SimulationExpander.IsExpanded Then
OccupiedHeight += SimulationExpander.ActualHeight
Else
Dim SimulationExpanderContent As FrameworkElement = DirectCast(SimulationExpander.Content, FrameworkElement)
SimulationExpanderContent.Measure(New Size(Double.PositiveInfinity, Double.PositiveInfinity))
OccupiedHeight += (SimulationExpander.ActualHeight - SimulationExpanderContent.DesiredSize.Height)
End If
OccupiedHeight += GenerateButton.ActualHeight
'Aggiungo altezza OperationsList header Expander
If Not OperationsListExpander.IsExpanded Then
OccupiedHeight += OperationsListExpander.ActualHeight
Else
Dim OperationsListExpanderContent As FrameworkElement = DirectCast(OperationsListExpander.Content, FrameworkElement)
OperationsListExpanderContent.Measure(New Size(Double.PositiveInfinity, Double.PositiveInfinity))
OccupiedHeight += (OperationsListExpander.ActualHeight - OperationsListExpanderContent.DesiredSize.Height)
End If
If Not OperationParametersExpander.IsExpanded Then
OccupiedHeight += OperationParametersExpander.ActualHeight
Else
Dim OperationParametersExpanderContent As FrameworkElement = DirectCast(OperationParametersExpander.Content, FrameworkElement)
OperationParametersExpanderContent.Measure(New Size(Double.PositiveInfinity, Double.PositiveInfinity))
OccupiedHeight += (OperationParametersExpander.ActualHeight - OperationParametersExpanderContent.DesiredSize.Height)
End If
'' Aggiungo altezza contenuto OperationParameters che però è fuori dallo Stackpanel
'OperationFirstParametersStackPanel.Measure(New Size(Double.PositiveInfinity, Double.PositiveInfinity))
'If OperationFirstParametersStackPanel.DesiredSize.Height <> 0 Then
' OccupiedHeight += OperationFirstParametersStackPanel.DesiredSize.Height
'Else
' ' aggiungo il valore calcolato provando se non viene calcolato dal sistema al momento
' OccupiedHeight += 10
'End If
'OperationParametersStackPanel.MaxHeight = OptionPanelViewStackPanel.MaxHeight - OccupiedHeight
End Sub
' Funzione che permette di trovare il primo contenitore di tipo T di un elemento grafico dependencyObject
Public Function FindAncestor(Of T As Class)(dependencyObject As DependencyObject) As T
Dim target As DependencyObject = dependencyObject
Do
target = LogicalTreeHelper.GetParent(target)
Loop While target IsNot Nothing AndAlso Not (TypeOf target Is T)
If IsNothing(target) Then
target = dependencyObject
Do
target = VisualTreeHelper.GetParent(target)
Loop While target IsNot Nothing AndAlso Not (TypeOf target Is T)
End If
Return TryCast(target, T)
End Function
End Class