Akash Gutha
Akash Gutha

Reputation: 599

navigating between pages using radio buttons in winrt

i'm trying to navigate between pages while toggling the radio buttons like the tab control. i've tries a few ways.Here they are

first the xaml

<StackPanel>
        <RadioButton Content="navigateto1" Checked="RadioButton_Checked"/>
        <RadioButton Content="navigateto2"
                     Checked="RadioButton_Checked_1"/>

        <Frame x:Name="contentframe">

        </Frame>
    </StackPanel>

then the code behind

private void RadioButton_Checked( object sender, RoutedEventArgs e ) { var _frame = contentframe.Content as Frame; if (_frame!=null) { _frame.Navigate(typeof(navPage)); } }

    private void RadioButton_Checked_1( object sender, RoutedEventArgs e )
    {
        var _frame = contentframe.Content as Frame;
        if (_frame!=null)
        {
            _frame.Navigate(typeof(navPage));
        }
     }

the frame is returned as null no matter what i do .. and it throws a nullreference exception on the content frame .. i've even tried including grid and other controls inside that frame even then i get a nulref exception.

what's the problem . why is it returning null? and is it safe to have a frame inside a page .. since it would be cascading two frames?

Upvotes: 0

Views: 119

Answers (1)

Walt Ritscher
Walt Ritscher

Reputation: 7037

You need to cast _contentFrame, not _contentFrame.Content.

var _frame = contentframe as Frame;

Upvotes: 2

Related Questions