单击按钮更改UserControl(导航而不重新加载整个页面?)

时间:2014-10-17 14:39:25

标签: c# xaml navigation windows-phone-8.1

我想通过点击按钮(我不想重新加载整个页面)在用户控件之间导航

我有一个空白的usercontrol

<Grid x:Name="Content" Grid.Row="1" Background="#FF1A7E1F">
    <UserControl x:Name="MainConent"/>                    
</Grid>

我想以编程方式将此用户控件设置为现有用户控件,例如

private void Button_Click_1(object sender, RoutedEventArgs e)
{
    MainConent.Equals(new MainControl()); // maincontrol is a usercontrol
} 

但遗憾的是,这并不起作用....有没有办法导航而无需重新加载整个页面?

1 个答案:

答案 0 :(得分:0)

//你有没有检查Equals的目的?

首先,您必须删除Grid的当前内容,然后设置新内容。

private void Button_Click_1(object sender, RoutedEventArgs e)
{
    Content.Children.Clear();
    Content.Children.Add(new MainControl());
} 
相关问题