I have a procedure to find the parent window, but in the following case it does not work. The toolwindow says it has no parents????
Am i doing something wrong?
The example has been simplified.
<ribbon:RibbonWindow x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:docking="http://schemas.actiprosoftware.com/winfx/xaml/docking"
xmlns:local="clr-namespace:WpfApplication1"
xmlns:ribbon="http://schemas.actiprosoftware.com/winfx/xaml/ribbon"
Title="MainWindow" Height="350" Width="525">
<Grid>
<DockPanel >
<docking:ToolWindowContainer>
<docking:ToolWindow>
<Grid>
<Button Width="73" Height="23" Name="rr">click</Button>
</Grid>
</docking:ToolWindow>
</docking:ToolWindowContainer>
</DockPanel>
</Grid>
</ribbon:RibbonWindow>
Private Sub rr_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles rr.Click
Dim Owner As Window = FindParentWindow(Me)
End Sub
Public Shared Function FindParentWindow(ByVal CurrentElement As Object) As DependencyObject
On Error Resume Next
Dim P As Object = Nothing
If TypeOf CurrentElement.parent Is ContentControl Then
P = CurrentElement.parent
Else
P = VisualTreeHelper.GetParent(CurrentElement)
End If
If IsNothing(P) Then
Return Nothing 'not found, end of tree
Else
If P.GetType Is GetType(Window) OrElse P.GetType Is GetType(RibbonWindow) OrElse P.GetType.BaseType Is GetType(Window) OrElse P.GetType.IsSubclassOf(GetType(Window)) Then 'found a visual of the desired type!
Return P
Else
Return FindParentWindow(P)
End If
End If
End Function