Browse Source

Теперь кнопка "Регистрация" переводит на Page2, а кнопка "Назад" появляется только тогда, когда нужно перейти на AuthPage

Ethosa 3 years ago
parent
commit
12acc40cbe

+ 2 - 2
Тураев_БД 11.20.1/MainWindow.xaml

@@ -16,8 +16,8 @@
             <ColumnDefinition/>
         </Grid.ColumnDefinitions>
         <Rectangle Fill="#FFF4F4F5" Grid.Row="2" StrokeThickness="0"/>
-        <Button Content="Назад" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="75"/>
-        <Frame Content="MainFrame" Source="Pages/AuthPage.xaml" Grid.Row="1"/>
+        <Button x:Name="ButtonBack" Content="Назад" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="75" Click="ButtonBack_Click"/>
+        <Frame x:Name="MainFrame" Content="MainFrame" Source="Pages/AuthPage.xaml" Grid.Row="1" Navigated="MainFrame_OnNavigated"/>
 
     </Grid>
 </Window>

+ 21 - 0
Тураев_БД 11.20.1/MainWindow.xaml.cs

@@ -12,6 +12,7 @@ using System.Windows.Media;
 using System.Windows.Media.Imaging;
 using System.Windows.Navigation;
 using System.Windows.Shapes;
+using Тураев_БД_11._20._1.Pages;
 
 namespace Тураев_БД_11._20._1
 {
@@ -25,5 +26,25 @@ namespace Тураев_БД_11._20._1
             InitializeComponent();
             ///izmenenie
         }
+
+        private void MainFrame_OnNavigated(object sender, NavigationEventArgs e)
+        {
+            if (!(e.Content is Page page)) return;
+            this.Title = $"LESSON - {page.Title}";
+
+            if (page is AuthPage)
+            {
+                ButtonBack.Visibility = Visibility.Hidden;
+            }
+            else
+            {
+                ButtonBack.Visibility = Visibility.Visible;
+            }
+        }
+
+        private void ButtonBack_Click(object sender, RoutedEventArgs e)
+        {
+            if (MainFrame.CanGoBack) MainFrame.GoBack();
+        }
     }
 }

+ 1 - 1
Тураев_БД 11.20.1/Pages/AuthPage.xaml

@@ -26,7 +26,7 @@
         <TextBox x:Name="TextBoxLogin" Grid.Column="2" Height="27" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Grid.Row="1"/>
         <Label Content="Пароль" Grid.Column="1" Grid.Row="1" VerticalAlignment="Top" Height="26" Margin="0,31,0,0"/>
         <Button Click="ButtonEnter_OnClick" Content="Вход" Grid.Column="2" Margin="0,65,0,0" Grid.Row="1" VerticalAlignment="Top"/>
-        <Button Content="Регистрация" Grid.Column="2" Margin="0,90,0,0" Grid.Row="1" VerticalAlignment="Top"/>
+        <Button Content="Регистрация" Grid.Column="2" Margin="0,90,0,0" Grid.Row="1" VerticalAlignment="Top" Click="ButtonRegistration_OnClick"/>
         <PasswordBox x:Name="PasswordBox" Grid.Column="2" Margin="0,32,0,0" Grid.Row="1" VerticalAlignment="Top" Height="25"/>
 
     </Grid>

+ 5 - 0
Тураев_БД 11.20.1/Pages/AuthPage.xaml.cs

@@ -33,5 +33,10 @@ namespace Тураев_БД_11._20._1.Pages
                 return;
             }
         }
+
+        private void ButtonRegistration_OnClick(object sender, RoutedEventArgs e)
+        {
+            NavigationService?.Navigate(new Page2());
+        }
     }
 }

+ 14 - 0
Тураев_БД 11.20.1/Pages/Page2.xaml

@@ -0,0 +1,14 @@
+<Page x:Class="Тураев_БД_11._20._1.Pages.Page2"
+      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:Тураев_БД_11._20._1.Pages"
+      mc:Ignorable="d" 
+      d:DesignHeight="450" d:DesignWidth="800"
+      Title="Page2">
+
+    <Grid>
+        
+    </Grid>
+</Page>

+ 28 - 0
Тураев_БД 11.20.1/Pages/Page2.xaml.cs

@@ -0,0 +1,28 @@
+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 Тураев_БД_11._20._1.Pages
+{
+    /// <summary>
+    /// Логика взаимодействия для Page2.xaml
+    /// </summary>
+    public partial class Page2 : Page
+    {
+        public Page2()
+        {
+            InitializeComponent();
+        }
+    }
+}

+ 7 - 0
Тураев_БД 11.20.1/Тураев_БД 11.20.1.csproj

@@ -75,11 +75,18 @@
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
     </Page>
+    <Page Include="Pages\Page2.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
   </ItemGroup>
   <ItemGroup>
     <Compile Include="Pages\AuthPage.xaml.cs">
       <DependentUpon>AuthPage.xaml</DependentUpon>
     </Compile>
+    <Compile Include="Pages\Page2.xaml.cs">
+      <DependentUpon>Page2.xaml</DependentUpon>
+    </Compile>
     <Compile Include="Properties\AssemblyInfo.cs">
       <SubType>Code</SubType>
     </Compile>