【问题标题】:Navigating between pages in wpf not working在 wpf 中的页面之间导航不起作用
【发布时间】:2017-02-12 12:38:21
【问题描述】:

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

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

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

窗口:

页面:

但我买的是白色的。

第 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方面我什么都没写。

【问题讨论】:

  • page1 的代码是什么?
  • 我将其添加到问题中。

标签: c# wpf navigation


【解决方案1】:

您需要将 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,你应该能够看到它。

【讨论】:

  • 然后请发布 Window1.xaml 的标记,因为它确实对我有用。
猜你喜欢
  • 1970-01-01
  • 2021-12-08
  • 1970-01-01
  • 2020-08-02
  • 1970-01-01
  • 1970-01-01
  • 2015-10-19
  • 1970-01-01
  • 2014-05-30
相关资源
最近更新 更多