Как заставить файл XAML открыть другой файл XAML - PullRequest
0 голосов
/ 24 сентября 2018

Я пытаюсь создать приложение WPF, и я хотел бы знать, как заставить один файл xaml открывать другой файл xaml при нажатии кнопки.

РЕДАКТИРОВАТЬ: Я пробовал:

this.Frame.Navigate(typeof(Window2));

Мой код для MainWindow.xaml.cs:

using System; // unused
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation; // unused

namespace WindowRemake
{

/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class Qwerty : Window
{
    public Qwerty()
    {
        InitializeComponent();
    }

    private void Button_Click_1(object sender, RoutedEventArgs e)
    {

        if (WindowsOption1.IsChecked == true)
        {
            Windows1 win = new Windows1();
            win.ShowDialog();
        }
        // add later versions when i can
    }

    private string UsernameValue = string.Empty;

    private void Username_TextChanged(object sender, TextChangedEventArgs e)
    {
        UsernameValue = Username.Text;
    }
}
}

И мой код для MainWindow.xaml:

<Window x:Name="ControlPanel" x:Class="Windows3Remake.Qwerty"
    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:WindowRemake"
    mc:Ignorable="d"
    Title="Control Panel" Height="450" Width="800" Cursor="Hand">

    <Grid Cursor="Hand">
        <Button x:Name="StartWindows" Content="Boot Windows" HorizontalAlignment="Left" Margin="77,84,0,0" VerticalAlignment="Top" Width="99" FontWeight="Bold" Cursor="Hand"/>
        <Label x:Name="LabelSetting" Content="Boot Options" HorizontalAlignment="Left" Margin="635,73,0,0" VerticalAlignment="Top" Cursor="Help"/>
        <TextBox x:Name="Username" HorizontalAlignment="Left" Height="23" Margin="595,117,0,0" TextWrapping="Wrap" Text="Username" VerticalAlignment="Top" Width="120"/>
        <RadioButton x:Name="WindowsOption1" Content="Windows 1.0" HorizontalAlignment="Left" Margin="630,161,0,0" VerticalAlignment="Top" IsChecked="True" Cursor="Hand"/>
    </Grid>
</Window>

РЕДАКТИРОВАТЬ 2: Я использую WPF по умолчанию, который можно использовать при выборе «Новый проект» в Visual Studio 2017

РЕДАКТИРОВАТЬ 3: Вот код для Windows1.xaml:

<Window x:Name="ControlPanel" x:Class="Windows3Remake.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:Windows3Remake"
        mc:Ignorable="d"
        Title="Options" Height="450" Width="800" Cursor="Hand">
    <Grid Cursor="Hand">

    </Grid>
</Window>

И код для Windows1.xaml.cs:

using System;
using System.Windows; // all imports are unused except for this one
using System.Windows.Controls;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Windows3Remake
{
    public partial class Windows1 : Window
    {
    }
}

РЕДАКТИРОВАТЬ

Я решил это.

1 Ответ

0 голосов
/ 25 сентября 2018
ButtonClick()
{
    Windows1 win = new Windows1();
    win.ShowDialog();
}

Это работает по вашему требованию?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...