We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Accessing UserControl Views from within MainWindow.cs

I'm new to WPF so bear with me if it's something really obvious but... I am using something similar to your Lazy Loading Demo. My tab control is located in MainWindow.xaml and it contains a few views (user controls) within the XAML as well.  I want to know if there's a way to access the public methods on the views from the MainWindow form? Basically what I'm trying to accomplish is to refresh a grid on the corresponding view once the user clicks on the tab. Since the view is already loaded, I can't use the view's Loaded event nor its constructor and since it's technically visible, I can't use the IsVisibleChanged event so I wanted to try and use the TabControl's SelectedIndexChanged event to figure out which tab was clicked, and then call the corresponding view's Refresh() method.

My relevant MainWindow.xaml Code is:

        <syncfusion:TabControlExt IsLazyLoaded="True" x:Name="TabControl" SelectedIndexChanged="TabControl_SelectedIndexChanged">
            <syncfusion:TabItemExt x:Name="CurrentVisitorsButton" Header="Current Visitors" Height="27">
                <views:CurrentVisitorsView/>
            </syncfusion:TabItemExt>
            <syncfusion:TabItemExt x:Name="VisitorHistoryButton" Header="Visitor History">
                <views:VisitorHistoryView/>
            </syncfusion:TabItemExt>
            <syncfusion:TabItemExt Header="Visitor Details"/>
        </syncfusion:TabControlExt>



Thanks for any help!

2 Replies

MA Muthukumar A Syncfusion Team August 4, 2014 06:12 AM UTC

Hi Nick,

We have created a sample which tries to meet your requirement. Please have it from below location.
In this sample we have used to SelectedItemChanged event of TabControlExt to determine the Selected UserControl and the relevant method get called using reflection.

Thanks,
Muthukumar A

 

 


Attachment: TabControl_127811649709340_a4f3e8cd.zip


NP Nick Posey August 4, 2014 12:31 PM UTC

Thanks, that worked perfectly!

Loader.
Up arrow icon