c# - 如何修复 WPF 中的导航/帧错误?错误 #CS1061
问题描述
我正在尝试设置一个导航页面,里面有一个框架,但我遇到了这个错误,我似乎无法摆脱。我的框架已停止工作并显示我已连接到它们的页面。
我已尝试查找此错误CS1061
并尝试查看错误在哪里。它似乎与Navigated="Frame_Navigated
MainWindow.xaml 中的冲突。也许有人可以指出我到底出了什么问题?它以前工作过。
MainWindow.xaml.cs 代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace TataSteel_Gamification_01
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
//Display Items in Frame
Loaded += Window_Loaded;
}
Boolean MenuToggle = true;
private void Window_Loaded(object sender, RoutedEventArgs e)
{
//Open the Start Frame
frame.NavigationService.Navigate(new Page1());
}
private void Btn_Page1_Click(object sender, RoutedEventArgs e)
{
//Open Page 1
frame.NavigationService.Navigate(new Page1());
}
MainWindow.xaml 代码(去掉不必要的部分):
<Window x:Name="ApplicationFrame" x:Class="TataSteel_Gamification_01.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:TataSteel_Gamification_01"
mc:Ignorable="d"
Title="MainWindow" Height="1200" Width="1920" Background="#FF1C2431">
<Grid x:Name="Grid_Display" ShowGridLines="False">
<Viewbox x:Name="Viewbox_Frame" Grid.Column="1" Grid.Row="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Frame x:Name="frame" Content="Frame" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" NavigationUIVisibility="Hidden" Navigated="Frame_Navigated" Height="1170" Width="1435"/>
</Viewbox>
</Grid>
我希望之后的结果将是导航再次起作用,因此我可以在框架内显示页面而不会出现任何错误。
解决方案
Navigated="Frame_Navigated"
Frame_Navigated 是实际导航框架时调用的函数。您似乎没有在MainWindow.xaml.cs中实现它
这是您在 .cs 文件中缺少的内容:
private void Frame_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e)
{
// your code to handle navigated frame
}
推荐阅读
- python - 通过具有 IOB 格式的 NLTK 获取斯坦福 NER 结果
- ionic3 - ionic3 错误 AndroidManifest.xml:53:66-112 需要占位符替换,但没有值
提供? - python - 如何在 Python 中从一页中抓取和索引多个表?
- reactjs - React + Axios 进度条
- build - 最小的 Yocto 图像发行功能
- sql - 在不知道每个表中哪些字段是唯一的情况下,如何在使用 T-SQL 的连接中从每个表中检索不同行的计数?
- node.js - 无法使用 ng serve 运行 Angular 应用程序
- c++ - 为什么当我尝试从成员函数调用构造函数时 IDE 会给出警告?
- c# - 向玩家位置实例化子弹
- tensorflow - 是否有任何工具/库可以将 tensorflow lstm 模型转换为 .mlmodel 格式以在 iOS 应用程序中运行