通过WPF应用程序中的“后退”按钮进行导航

时间:2019-05-07 14:46:43

标签: c# wpf xaml desktop-application

我正在开发桌面应用程序,我想向后退按钮添加功能,这些功能会将我带到MainControl.xaml页面。

我尝试了一些在线代码,但没有用。在C#和WPF中,我是一个相对较新的编码器。

我已成功添加按钮,如下所示:

<local:BasePage x:TypeArguments="core:TemplateScanViewModel"  x:Class="PFU.ScanToSage.TemplateScanControl"
         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" 
         xmlns:local="clr-namespace:PFU.ScanToSage"
         xmlns:core="clr-namespace:PFU.ScanToSage.Core;assembly=PFU.ScanToSage.Core"
         mc:Ignorable="d" 
             Loaded="TemplateScan_Loaded"
         Background="{DynamicResource BackgroundVeryLightBrush}"
         >

<Grid Background="{DynamicResource ForegroundLightBrush}"
      Margin="10 0 10 0">

    <Grid.RowDefinitions>
        <!-- Name -->
        <RowDefinition Height="10" />
        <RowDefinition Height="auto" />
        <!-- Use template image-->
        <RowDefinition Height="10" />
        <RowDefinition Height="auto" />
        <!-- scan sample & load from memory -->
        <RowDefinition Height="10" />
        <RowDefinition Height="auto" />
        <RowDefinition Height="20" />
    </Grid.RowDefinitions>

    <!-- Name -->
    <GroupBox x:Name="nameGroupbox"
               Visibility="Hidden"
              VerticalAlignment="Top"
              Grid.Row="1"
              Header="Name"
              FontSize="16"
              FontWeight="SemiBold"
                  HorizontalAlignment="Stretch" FontFamily="Segoe UI Semibold"
               >
        <GroupBox.Foreground>
            <SolidColorBrush Color="#FF00587D"/>
        </GroupBox.Foreground>

        <TextBox MinWidth="80" 
                 x:Name="nameTxt"
                             Grid.Column="2"
                     Grid.Row="7"
                         Style="{StaticResource GrayTextBox}"
                         Margin="2"
                         />

    </GroupBox>

    <!-- Use Template Image-->
    <Button Content="Use Template"
            Visibility="Hidden"
            Grid.Row="3"
            x:Name="useTemplateBtn"
            FontSize="{StaticResource FontSizeRegular}"
            HorizontalAlignment="Center" Click="useTemplateBtn_Click" Background="#FF00A5E3" FontFamily="Segoe UI Semibold"
            />

    <!-- Scan & Load from memory-->
    <Grid Grid.Row="5">
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>

        <!-- Scan Sample-->
        <Button Content="Scan Sample"
            Grid.Column="0"
                x:Name="scanSampleBtn"
            FontSize="{StaticResource FontSizeRegular}" Click="scanSampleBtn_Click" Background="#FF00A5E3" FontFamily="Segoe UI Semibold" Grid.ColumnSpan="3" Margin="80,-46,93,66"
            />

        <!-- Load from memory-->
        <Button Content="Load Template"
                x:Name="loadFromMemoryBtn"
            FontSize="{StaticResource FontSizeRegular}" Click="loadFromMemoryBtn_Click" Background="#FF00A5E3" FontFamily="Segoe UI Semibold" Grid.ColumnSpan="3" Margin="80,0,93,20"
            />
    </Grid>
    <Button x:Name="BackButtonTemp" Content="Back" HorizontalAlignment="Left" Height="26" Margin="19,10,0,0" Grid.Row="1" VerticalAlignment="Top" Width="85" FontSize="14" FontWeight="Bold" FontFamily="Segoe UI Semibold" Click="Button_Click"/>

</Grid>

代码是这样,但我不知道在括号内要添加什么

private void Button_Click(object sender, RoutedEventArgs e)
{
   "Go to MainControl.xaml"
}

我想知道如何添加一个有效的后退按钮。

Image of Application

0 个答案:

没有答案