From 172b45cf35df5fce2ad3339e1a040ebe04f6556f Mon Sep 17 00:00:00 2001 From: Emmanuele Sassi Date: Fri, 14 Oct 2016 18:51:15 +0000 Subject: [PATCH] =?UTF-8?q?EgtCAM5=20:=20-=20Aggiunte=20moltefunzionalit?= =?UTF-8?q?=C3=A0=20di=20gestione=20tabelle=20per=20Doors.=20-=20Migliorat?= =?UTF-8?q?a=20la=20Behaviour=20di=20Scroll=20per=20ListBox=20e=20aggiunta?= =?UTF-8?q?=20quella=20per=20DataGrid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AttachedBehaviours/ScrollIntoView.vb | 152 +++++ .../ScrollIntoViewForListBox.vb | 42 -- Constants/ConstDoors.vb | 6 + EgtCAM5.vbproj | 5 +- EgtCAM5Resources.xaml | 8 +- MTableDb/MTableDbView.xaml | 303 +++++++-- MTableDb/MTableDbViewModel.vb | 360 ++++++++++- MTableDb/MTableListBox.vb | 606 ++++++++++++++++-- MTableDb/TableUtility.vb | 71 ++ MachineModel.vb | 69 ++ MachiningsDbWindow/MachiningsDbViewModel.vb | 40 +- ProjectPage/DoorsPanel/DoorsPanelView.xaml | 2 +- .../MachiningTreeExpanderView.xaml | 2 +- .../OperationExpanderView.xaml.vb | 1 + 14 files changed, 1453 insertions(+), 214 deletions(-) create mode 100644 AttachedBehaviours/ScrollIntoView.vb delete mode 100644 AttachedBehaviours/ScrollIntoViewForListBox.vb create mode 100644 Constants/ConstDoors.vb create mode 100644 MTableDb/TableUtility.vb create mode 100644 MachineModel.vb diff --git a/AttachedBehaviours/ScrollIntoView.vb b/AttachedBehaviours/ScrollIntoView.vb new file mode 100644 index 0000000..879a2be --- /dev/null +++ b/AttachedBehaviours/ScrollIntoView.vb @@ -0,0 +1,152 @@ +Imports System.Windows.Interactivity +Imports System.Collections.Specialized + +Public Class ScrollIntoViewForListBox + Inherits Behavior(Of ListBox) + + Private ItemsSource As INotifyCollectionChanged + + Private ListControl As ListBox + + ''' + ''' When Beahvior is attached + ''' + Protected Overrides Sub OnAttached() + MyBase.OnAttached() + ListControl = Me.AssociatedObject + AddHandler Me.AssociatedObject.SelectionChanged, AddressOf AssociatedObject_SelectionChanged + End Sub + + + Private Sub AssociatedObject_CollectionChanged(sender As Object, e As System.Collections.Specialized.NotifyCollectionChangedEventArgs) + If ListControl.SelectedItem IsNot Nothing Then + Dim SelectedItemIndex As Integer = ListControl.Items.IndexOf(ListControl.SelectedItem) + ListControl.Dispatcher.BeginInvoke(DirectCast(Sub() + ListControl.UpdateLayout() + If ListControl.SelectedItem IsNot Nothing Then + ListControl.ScrollIntoView(ListControl.SelectedItem) + End If + End Sub, Action)) + If SelectedItemIndex > 0 Then + ListControl.Dispatcher.BeginInvoke(DirectCast(Sub() + ListControl.UpdateLayout() + ListControl.ScrollIntoView(ListControl.Items(SelectedItemIndex - 1)) + End Sub, Action)) + End If + If SelectedItemIndex < ListControl.Items.Count - 2 Then + ListControl.Dispatcher.BeginInvoke(DirectCast(Sub() + ListControl.UpdateLayout() + ListControl.ScrollIntoView(ListControl.Items(SelectedItemIndex + 1)) + End Sub, Action)) + End If + End If + End Sub + + ''' + ''' On Selection Changed + ''' + ''' + ''' + Private Sub AssociatedObject_SelectionChanged(sender As Object, e As SelectionChangedEventArgs) + If IsNothing(ItemsSource) Then + Dim CurrItemsSource As IEnumerable = Me.AssociatedObject.ItemsSource + ItemsSource = TryCast(CurrItemsSource, INotifyCollectionChanged) + AddHandler ItemsSource.CollectionChanged, AddressOf AssociatedObject_CollectionChanged + RemoveHandler Me.AssociatedObject.SelectionChanged, AddressOf AssociatedObject_SelectionChanged + + ' SE SI CAMBIA ITEMSSOURCE PERDE IL RIFERIMENTO E SMETTE DI FUNZIONARE + ' PER RIATTIVARLO USARE IL SEGUENTE CODICE COMMENTATO + 'ElseIf ItemsSource IsNot Me.AssociatedObject.ItemsSource Then + ' Dim PreviousItemsSourceList As INotifyCollectionChanged = TryCast(ItemsSource, INotifyCollectionChanged) + ' RemoveHandler PreviousItemsSourceList.CollectionChanged, AddressOf AssociatedObject_CollectionChanged + ' Dim CurrItemsSource As IEnumerable = Me.AssociatedObject.ItemsSource + ' ItemsSource = TryCast(CurrItemsSource, INotifyCollectionChanged) + ' AddHandler ItemsSource.CollectionChanged, AddressOf AssociatedObject_CollectionChanged + End If + End Sub + + ''' + ''' When behavior is detached + ''' + Protected Overrides Sub OnDetaching() + MyBase.OnDetaching() + 'RemoveHandler Me.AssociatedObject.SelectionChanged, AddressOf AssociatedObject_SelectionChanged + RemoveHandler ItemsSource.CollectionChanged, AddressOf AssociatedObject_CollectionChanged + End Sub + +End Class + +Public Class ScrollIntoViewForDataGrid + Inherits Behavior(Of DataGrid) + + Private ItemsSource As INotifyCollectionChanged + + Private ListControl As DataGrid + + ''' + ''' When Beahvior is attached + ''' + Protected Overrides Sub OnAttached() + MyBase.OnAttached() + ListControl = Me.AssociatedObject + AddHandler Me.AssociatedObject.SelectionChanged, AddressOf AssociatedObject_SelectionChanged + End Sub + + + Private Sub AssociatedObject_CollectionChanged(sender As Object, e As System.Collections.Specialized.NotifyCollectionChangedEventArgs) + If ListControl.SelectedItem IsNot Nothing Then + Dim SelectedItemIndex As Integer = ListControl.Items.IndexOf(ListControl.SelectedItem) + ListControl.Dispatcher.BeginInvoke(DirectCast(Sub() + ListControl.UpdateLayout() + If ListControl.SelectedItem IsNot Nothing Then + ListControl.ScrollIntoView(ListControl.SelectedItem) + End If + End Sub, Action)) + If SelectedItemIndex > 0 Then + ListControl.Dispatcher.BeginInvoke(DirectCast(Sub() + ListControl.UpdateLayout() + ListControl.ScrollIntoView(ListControl.Items(SelectedItemIndex - 1)) + End Sub, Action)) + End If + If SelectedItemIndex < ListControl.Items.Count - 2 Then + ListControl.Dispatcher.BeginInvoke(DirectCast(Sub() + ListControl.UpdateLayout() + ListControl.ScrollIntoView(ListControl.Items(SelectedItemIndex + 1)) + End Sub, Action)) + End If + End If + End Sub + + ''' + ''' On Selection Changed + ''' + ''' + ''' + Private Sub AssociatedObject_SelectionChanged(sender As Object, e As SelectionChangedEventArgs) + If IsNothing(ItemsSource) Then + Dim CurrItemsSource As IEnumerable = Me.AssociatedObject.ItemsSource + ItemsSource = TryCast(CurrItemsSource, INotifyCollectionChanged) + AddHandler ItemsSource.CollectionChanged, AddressOf AssociatedObject_CollectionChanged + RemoveHandler Me.AssociatedObject.SelectionChanged, AddressOf AssociatedObject_SelectionChanged + + ' SE SI CAMBIA ITEMSSOURCE PERDE IL RIFERIMENTO E SMETTE DI FUNZIONARE + ' PER RIATTIVARLO USARE IL SEGUENTE CODICE COMMENTATO + 'ElseIf ItemsSource IsNot Me.AssociatedObject.ItemsSource Then + ' Dim PreviousItemsSourceList As INotifyCollectionChanged = TryCast(ItemsSource, INotifyCollectionChanged) + ' RemoveHandler PreviousItemsSourceList.CollectionChanged, AddressOf AssociatedObject_CollectionChanged + ' Dim CurrItemsSource As IEnumerable = Me.AssociatedObject.ItemsSource + ' ItemsSource = TryCast(CurrItemsSource, INotifyCollectionChanged) + ' AddHandler ItemsSource.CollectionChanged, AddressOf AssociatedObject_CollectionChanged + End If + End Sub + + ''' + ''' When behavior is detached + ''' + Protected Overrides Sub OnDetaching() + MyBase.OnDetaching() + 'RemoveHandler Me.AssociatedObject.SelectionChanged, AddressOf AssociatedObject_SelectionChanged + RemoveHandler ItemsSource.CollectionChanged, AddressOf AssociatedObject_CollectionChanged + End Sub + +End Class diff --git a/AttachedBehaviours/ScrollIntoViewForListBox.vb b/AttachedBehaviours/ScrollIntoViewForListBox.vb deleted file mode 100644 index 7c4f6e4..0000000 --- a/AttachedBehaviours/ScrollIntoViewForListBox.vb +++ /dev/null @@ -1,42 +0,0 @@ -Imports System.Windows.Interactivity - -Public Class ScrollIntoViewForListBox - Inherits Behavior(Of ListBox) - - ''' - ''' When Beahvior is attached - ''' - Protected Overrides Sub OnAttached() - MyBase.OnAttached() - AddHandler Me.AssociatedObject.SelectionChanged, AddressOf AssociatedObject_SelectionChanged - End Sub - - ''' - ''' On Selection Changed - ''' - ''' - ''' - Private Sub AssociatedObject_SelectionChanged(sender As Object, e As SelectionChangedEventArgs) - If TypeOf sender Is ListBox Then - Dim listBox As ListBox = TryCast(sender, ListBox) - If listBox.SelectedItem IsNot Nothing Then - listBox.Dispatcher.BeginInvoke(DirectCast(Sub() - listBox.UpdateLayout() - If listBox.SelectedItem IsNot Nothing Then - listBox.ScrollIntoView(listBox.SelectedItem) - End If - - End Sub, Action)) - End If - End If - End Sub - ''' - ''' When behavior is detached - ''' - Protected Overrides Sub OnDetaching() - MyBase.OnDetaching() - RemoveHandler Me.AssociatedObject.SelectionChanged, AddressOf AssociatedObject_SelectionChanged - - End Sub - -End Class diff --git a/Constants/ConstDoors.vb b/Constants/ConstDoors.vb new file mode 100644 index 0000000..71f5562 --- /dev/null +++ b/Constants/ConstDoors.vb @@ -0,0 +1,6 @@ +Module ConstDoors + + Public Const S_OPERATIONS As String = "Operations" + Public Const S_GEOMETRYNAMES As String = "GeometryNames" + +End Module diff --git a/EgtCAM5.vbproj b/EgtCAM5.vbproj index e15ec6c..59904e4 100644 --- a/EgtCAM5.vbproj +++ b/EgtCAM5.vbproj @@ -120,22 +120,25 @@ - + + + MTableDbView.xaml + OptionsView.xaml diff --git a/EgtCAM5Resources.xaml b/EgtCAM5Resources.xaml index c958cd8..43290c2 100644 --- a/EgtCAM5Resources.xaml +++ b/EgtCAM5Resources.xaml @@ -33,6 +33,7 @@ + - - diff --git a/MTableDb/MTableDbView.xaml b/MTableDb/MTableDbView.xaml index 86d9279..f790d0b 100644 --- a/MTableDb/MTableDbView.xaml +++ b/MTableDb/MTableDbView.xaml @@ -1,6 +1,8 @@  - + - - + + + + + - + + + + +