0

我正在尝试从 WPF 应用程序中的 MainWindow 导航到不同的页面。MainWindow 只是有一些欢迎文本,我希望它在 4 秒后移动到另一个页面。计时器工作正常,但我收到一条错误消息,

“错误 1 ​​'UbiTutorial.MainWindow' 不包含 'Frame' 的定义,并且找不到接受 'UbiTutorial.MainWindow' 类型的第一个参数的扩展方法 'Frame'(您是否缺少 using 指令或程序集引用? ) c:\users\thomas\documents\visual studio 2012\Projects\UbiTutorial\UbiTutorial\MainWindow.xaml.cs 54 22 UbiTutorial"

在我的方法中

if (introTime > 4)
{
    this.Frame.Navigate(typeof(Touch));
}

Visual Studio 抱怨它的 Frame 部分。

4

1 回答 1

1

Frame是控件类型而不是控件实例,没有看到您的 Xaml 我不知道您添加的框架的名称是frame1什么,它可能默认为您需要使用它来访问导航方法。希望这会给你一个想法。

主窗口.xaml

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <Frame Height="100" HorizontalAlignment="Left" Margin="10,10,0,0" Name="frame1" VerticalAlignment="Top" Width="200" />
    </Grid>
</Window>

主窗口.xaml.cs

using System.Windows.Threading;

namespace WpfApplication1
{
     /// <summary>
     /// Interaction logic for MainWindow.xaml
     /// </summary>
     public partial class MainWindow : Window
     {
         DispatcherTimer introTime = new DispatcherTimer();
         public MainWindow()
         {
             InitializeComponent();
             introTime.Interval = TimeSpan.FromSeconds(4);
             introTime.Tick += new EventHandler(introTime_Tick);
             introTime.Start();
         }

         void introTime_Tick(object sender, EventArgs e)
         {
             //this.frame1.Navigate(new Uri(@"http://www.google.com"));
             this.frame1.Navigate(new UserControl1());
         }
     }
 }

UserControl1.xaml

<UserControl x:Class="WpfApplication1.UserControl1"
             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="300" d:DesignWidth="300" Background="Red" >
    <Grid>

    </Grid>
</UserControl>
于 2013-08-01T03:16:27.080 回答