[英]Navigation in C# XAML Not Working
前言:我在这里发布此消息,因为我在这里未收到任何回复: https : //social.msdn.microsoft.com/Forums/vstudio/en-US/5d7d4554-7d4b-45af-b02c-22ed0c7695a2 / navigation-in-c-xaml-not-working?forum = vsta
我知道Stackoverflow是更可靠的来源,因此我决定在此处重新发布。
我正在尝试使我的第一个应用程序成为VS,并且我希望它成为一个有关信息提示的信息应用程序(非常快地解决Rubik的样式多维数据集。)我现在只是在学习C#和XAML的基础知识,无法在页面之间导航。 我看过的所有教程都使用以下代码行:
this.Frame.Navigate(typeof(PLL), null);
但这给了我这个错误:
'Mainwindow'不包含'Frame'的定义,也找不到扩展方法'Frame'接受类型为'MainWindow'的第一个参数(您是否缺少using指令或程序集引用?我也想指出一点他们说要使用“空白应用程序”模板,但我似乎找不到-是不是在VS社区中呢?相反,我不得不使用WPF应用程序模板。
我究竟做错了什么? 如何使页面之间的这些链接正常工作?
以下是我的全部C#和XAML代码。
谢谢!
C#:
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 CubingGuide
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void GoToPLL(object sender, RoutedEventArgs e)
{
this.Frame.Navigate(typeof(PLL), null);
}
}
}
XAML:
<Window x:Class="CubingGuide.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:CubingGuide"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Button x:Name="GoToPLLButt" Margin="10,10,360,251" Content="PLL" Click="GoToPLL"/>
</Grid>
</Window>
如果要导航到Frame
则需要在XAML中创建Frame
对象(即,需要用“ PLL”填充框架)。
您需要MainPage.xaml中的Frame控件
<Window x:Class="WpfApplication1.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:WpfApplication1"
xmlns:Controls="clr-namespace:System.Windows.Controls;assembly=PresentationFramework"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Button x:Name="button" Content="Button" HorizontalAlignment="Left" Height="60" Margin="64,89,0,0" VerticalAlignment="Top" Width="135" Click="button_Click"/>
<Controls:Frame Name="MainFrame" NavigationUIVisibility="Hidden" >
</Controls:Frame>
</Grid>
</Window>
点击事件时,您只需要添加以下代码:
private void button_Click(object sender, RoutedEventArgs e)
{
MainFrame.Navigate(new Page1());
}
我希望这有帮助 :)
<Custom:Ribbon x:Name="ribbon" HorizontalAlignment="Left" Margin="0,10,0,0" VerticalAlignment="Top" Width="934">
<Custom:Ribbon.QuickAccessToolBar>
<Custom:RibbonQuickAccessToolBar>
<Custom:RibbonQuickAccessToolBar>
<Custom:RibbonSplitMenuItem Header="مرحله سوم"/>
</Custom:RibbonQuickAccessToolBar>
</Custom:Ribbon>
</Grid>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.