在 winrt 中使用单选按钮在页面之间导航
navigating between pages using radio buttons in winrt
我正在尝试在页面之间导航,同时切换选项卡控件之类的单选按钮。我已经尝试了一些 ways.Here 他们是
首先是xaml
<StackPanel>
<RadioButton Content="navigateto1" Checked="RadioButton_Checked"/>
<RadioButton Content="navigateto2"
Checked="RadioButton_Checked_1"/>
<Frame x:Name="contentframe">
</Frame>
</StackPanel>
然后是后面的代码
private void RadioButton_Checked(对象发送者,RoutedEventArgs e)
{
var _frame = contentframe.Content 作为框架;
如果(_frame!=空)
{
_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));
}
}
无论我做什么,框架都返回 null .. 并且它在内容框架上抛出 nullreference 异常 .. 我什至尝试在该框架内包含网格和其他控件,即使我得到 nulref 异常.
有什么问题。为什么它返回空值?在一个页面中放置一个框架是否安全...因为它会级联两个框架?
您需要投射 _contentFrame
,而不是 _contentFrame.Content
。
var _frame = contentframe as Frame;
我正在尝试在页面之间导航,同时切换选项卡控件之类的单选按钮。我已经尝试了一些 ways.Here 他们是
首先是xaml
<StackPanel>
<RadioButton Content="navigateto1" Checked="RadioButton_Checked"/>
<RadioButton Content="navigateto2"
Checked="RadioButton_Checked_1"/>
<Frame x:Name="contentframe">
</Frame>
</StackPanel>
然后是后面的代码
private void RadioButton_Checked(对象发送者,RoutedEventArgs e) { var _frame = contentframe.Content 作为框架; 如果(_frame!=空) { _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));
}
}
无论我做什么,框架都返回 null .. 并且它在内容框架上抛出 nullreference 异常 .. 我什至尝试在该框架内包含网格和其他控件,即使我得到 nulref 异常.
有什么问题。为什么它返回空值?在一个页面中放置一个框架是否安全...因为它会级联两个框架?
您需要投射 _contentFrame
,而不是 _contentFrame.Content
。
var _frame = contentframe as Frame;