Skip to content

Commit 3f1317f

Browse files
Working z-index change
1 parent baaf046 commit 3f1317f

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

VBAudioRouter/Controls/NodeControl.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
<StackPanel Background="#3F3F3F" CornerRadius="5" BorderThickness="1" BorderBrush="#efefef">
1515
<Grid Background="{x:Bind TitleBrush}" Padding="10,4,10,4"
16-
ManipulationMode="TranslateX, TranslateY" ManipulationDelta="UserControl_ManipulationDelta"
16+
ManipulationMode="TranslateX, TranslateY" ManipulationDelta="UserControl_ManipulationDelta" ManipulationStarted="Grid_ManipulationStarted"
1717
Tapped="Grid_Tapped">
1818
<TextBlock Text="{x:Bind Title}" FontSize="10" Foreground="White" />
1919
</Grid>

VBAudioRouter/Controls/NodeControl.xaml.vb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,16 @@ Namespace Controls
6464
End Sub
6565

6666
Private Sub Grid_Tapped(sender As Object, e As TappedRoutedEventArgs)
67+
Me.BringToFront()
6768
If Window.Current.CoreWindow.GetKeyState(Windows.System.VirtualKey.Control).HasFlag(CoreVirtualKeyStates.Down) Then
6869
If NodeContent.GetType() = GetType(OutputNodeControl) Then Exit Sub
6970
ConnectionHelper.DisposeNode(Me)
7071
End If
7172
End Sub
73+
74+
Private Sub Grid_ManipulationStarted(sender As Object, e As ManipulationStartedRoutedEventArgs)
75+
Me.BringToFront()
76+
End Sub
7277
End Class
7378

7479
End Namespace

VBAudioRouter/Utils/Extensions.vb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,35 @@ Namespace Utils
2929
Public Function FindNameRecursive(ByRef ele As FrameworkElement, name As String) As FrameworkElement
3030
Return FindNameRecursive(Of FrameworkElement)(ele, name)
3131
End Function
32+
33+
''' <summary>
34+
''' https://stackoverflow.com/a/24120993/15213858
35+
''' </summary>
36+
''' <param name="this"></param>
37+
<Extension>
38+
Public Sub BringToFront(ByRef this As FrameworkElement)
39+
Try
40+
Dim parent As Panel = this.Parent
41+
Dim currentIndex As Integer = Canvas.GetZIndex(this)
42+
Dim zIndex As Integer = 0
43+
Dim maxZ As Integer = 0
44+
Dim child As FrameworkElement
45+
46+
For i As Integer = 0 To parent.Children.Count - 1
47+
If TypeOf parent.Children(i) Is UserControl AndAlso parent.Children(i) IsNot this Then
48+
child = TryCast(parent.Children(i), UserControl)
49+
zIndex = Canvas.GetZIndex(child)
50+
maxZ = Math.Max(maxZ, zIndex)
51+
52+
If zIndex >= currentIndex Then
53+
Canvas.SetZIndex(child, zIndex - 1)
54+
End If
55+
End If
56+
Next
57+
58+
Canvas.SetZIndex(this, maxZ)
59+
Catch : End Try
60+
End Sub
3261
End Module
3362

3463
Public Class ColorTranslator

0 commit comments

Comments
 (0)