0

Foreword: I'm posting this here as I didn't get any replies to my post here: https://social.msdn.microsoft.com/Forums/vstudio/en-US/5d7d4554-7d4b-45af-b02c-22ed0c7695a2/navigation-in-c-xaml-not-working?forum=vsta

I know Stackoverflow is a much more reliable source, so I decided to repost it here.

I'm trying to make make my first app in VS, and I want it to just be an informational App about cubing (Solving Rubik's style cubes very fast.) I am just learning the basics of C# and XAML at the moment, but am unable to get navigation between pages. All tutorials I have seen say use the line of code:

this.Frame.Navigate(typeof(PLL), null);

But it gives me this error:

'Mainwindow' does not contain a definition for 'Frame' and no extension method 'Frame' accepting a first argument of type 'MainWindow' could be found (are you missing a using directive or an assembly reference? I also want to point out that they say to use the 'Blank App' Template, but I can't seem to find that - is it not in VS community? Instead, I had to use the WPF app template.

What am I doing wrong? How can I get these links between pages working?

Below is the whole of my C# and XAML code.

Thanks!

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>
ganchito55
  • 3,559
  • 4
  • 25
  • 46
MattyAB
  • 365
  • 2
  • 9
  • 19
  • 1
    You may want to read this article first: [Navigation Overview](https://msdn.microsoft.com/en-us/library/ms750478(v=vs.100).aspx). – Clemens Feb 09 '16 at 18:26
  • I have no idea what the `Frame` object is referring to, but it is not a property on the Window object. Typically if I want to implement navigation in a WPF application, I go with [this style](http://stackoverflow.com/a/12216068/302677) – Rachel Feb 09 '16 at 21:16

3 Answers3

0

You need to create Frame object in XAML if you want to navigate to the Frame(i.e. you need to populate the frame with your "PLL").

WindyHen
  • 318
  • 2
  • 6
0

you need a Frame control in MainPage.xaml

<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>

On click event you just need to add this code:

    private void button_Click(object sender, RoutedEventArgs e)
    {
        MainFrame.Navigate(new Page1());
    }

I hope this helps :)

Csar
  • 1
  • 2
  • When I add this code, I get a blue line saying 'the namespace prefix 'controls' is not defined in the opening XAML frame clause. I also get an error in the C# saying 'The name 'MainFrame' does not exist in the current context. Any idea how to fix this? – MattyAB Feb 10 '16 at 20:25
  • Now the XAML pseudo-error has changed to saying 'Frame is not supported in WPF Projects'... I don't know what's changed D: – MattyAB Feb 10 '16 at 20:51
0
    <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>