New to Telerik UI for WPF? Download free 30-day trial

Set StaysOpen Property to False of Parent Popup of FilteringControl

Environment

Product Version 2023.2.606
Product RadVirtualGrid for WPF

Description

How to set the StaysOpen property of the RadVirtualGrid FilteringControl's parent Popup element.

Solution

To achieve this requirement, utilize the EventManager.RegisterClassHandler method to subscribe to the Loaded event of each FilteringControl instance:

Subscribing to Loaded event of FilteringControl

public partial class MainWindow : Window 
{ 
    static MainWindow() 
    { 
        EventManager.RegisterClassHandler(typeof(FilteringControl), LoadedEvent, new RoutedEventHandler (OnLoaded)); 
    } 
} 
Public Partial Class MainWindow 
    Inherits Window 
 
    Private Shared Sub New() 
        EventManager.RegisterClassHandler(GetType(FilteringControl), LoadedEvent, New RoutedEventHandler(OnLoaded)) 
    End Sub 
End Class 

In the added event handler, retrieve the parent Popup element of the FilteringControl instance using the ParentOfType extension method. Then, set its StaysOpen property to False.

Set the StaysOpen property of the parent Popup

public partial class MainWindow : Window { static MainWindow() { EventManager.RegisterClassHandler(typeof(FilteringControl), LoadedEvent, new RoutedEventHandler(OnLoaded)); }

    private static void OnLoaded(object sender, RoutedEventArgs e) 
    { 
        FilteringControl filteringControl = (FilteringControl)sender; 
 
        Popup popup = filteringControl.ParentOfType<Popup>(); 
 
        if (popup != null) 
        { 
            popup.StaysOpen = false; 
        } 
    } 
} 
Public Partial Class MainWindow 
    Inherits Window 
 
    Private Shared Sub New() 
        EventManager.RegisterClassHandler(GetType(FilteringControl), LoadedEvent, New   RoutedEventHandler(AddressOf OnLoaded)) 
    End Sub 
 
    Private Shared Sub OnLoaded(ByVal sender As Object, ByVal e As RoutedEventArgs) 
        Dim filteringControl As FilteringControl = CType(sender, FilteringControl) 
        Dim popup As Popup = filteringControl.ParentOfType(Of Popup)() 
 
        If popup IsNot Nothing Then 
            popup.StaysOpen = False 
        End If 
    End Sub 
End Class 
In this article