在wpf无法正常工作的页面之间导航

时间:2017-02-12 12:38:21

标签: c# wpf navigation

我做过最简单的事情。我打开一个新窗口并在其中放置一个框架,我想在框架中显示一个页面。 窗口代码:

public partial class Window1 : Window
{
    public Window1()
    {
        InitializeComponent();
        Page1 p = new Page1();
        navigator.NavigationService.Navigate(p);
    }
}

导航器是框架,在Page1中我有黑色背景颜色可以看出差异。当我运行它时,我仍然看到窗口,而不是应该在框架内的页面。为什么这不起作用?

窗口:enter image description here

页:enter image description here

但我得到白色的。

第1页的代码:

<Page x:Class="test.Page1"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
  xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
  mc:Ignorable="d" 
  d:DesignHeight="269" d:DesignWidth="292"
Title="Page1">

<Grid Background="Black">

</Grid>

在cs方面,我没有写任何东西。

1 个答案:

答案 0 :(得分:0)

您需要将Page的Content属性设置为能够实际看到它的内容:

<Page x:Class="test.Page1"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
  xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
  mc:Ignorable="d" 
  d:DesignHeight="269" d:DesignWidth="292"
  Title="Page1">
    <Grid Background="Black">
        <TextBlock>PAGE1</TextBlock>
    </Grid>
</Page>

看不到空的黑色网格,但是如果你在其中放置一个TextBlock,你应该可以看到它。

相关问题