我是C#的新手开发人员,遇到了无法解决的问题。 我想使用标签上的click事件定向到另一个xaml文件。但是如何在不打开新窗口的情况下显示multiplayer.xaml。
第一个代码是gameMenu.xaml代码,第二个代码是gameMenu.xaml.cs,第三个代码是multiPlayer.xaml
gameMenu.xaml
Window x:Class="menu.gameMenu"
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:menu"
mc:Ignorable="d"
Title="Menu | Memory Game" Height="450" Width="800">
<!--Screen Layout-->
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="1.5*" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="0.25*" />
<RowDefinition Height="1*" />
<RowDefinition Height="0.25*" />
</Grid.RowDefinitions>
<!--Menu Title-->
<TextBlock Grid.Column="1" Grid.Row="1" Text="Memory Game" FontWeight="Bold" TextAlignment="Center" Margin="0 10"></TextBlock>
<!--Menu Items-->
<StackPanel Grid.Column="1" Grid.Row="1" VerticalAlignment="Center">
<Label Name="singlePlayer" Grid.Column="1" Grid.Row="1" HorizontalContentAlignment="Center" MouseLeftButtonUp="singlePlayer_Click" Content="Single Player"></Label>
<Label Name="multiPlayer" Grid.Column="1" Grid.Row="1" HorizontalContentAlignment="Center" MouseLeftButtonUp="multiPlayer_Click" Content="Multi Player"></Label>
<Label Name="highScores" Grid.Column="1" Grid.Row="1" HorizontalContentAlignment="Center" MouseLeftButtonUp="highScores_Click" Content="High Scores"></Label>
<Label Name="features" Grid.Column="1" Grid.Row="1" HorizontalContentAlignment="Center" MouseLeftButtonUp="features_Click" Content="Features"></Label>
</StackPanel>
</Grid>
</Window>
gameMenu.xaml.cs
namespace menu
{
public partial class gameMenu : Window
{
public gameMenu()
{
InitializeComponent();
}
protected void singlePlayer_Click(object sender, RoutedEventArgs e)
{
singlePlayer.Content = "Clicked";
}
protected void multiPlayer_Click(object sender, RoutedEventArgs e)
{
multiPlayer.Content = "Clicked";
multiPlayer multiPlayerScreen = new multiPlayer();
multiPlayerScreen.Show();
}
protected void highScores_Click(object sender, RoutedEventArgs e)
{
highScores.Content = "Clicked";
}
protected void features_Click(object sender, RoutedEventArgs e)
{
features.Content = "Clicked";
}
}
}
multiPlayer.xaml
<Window x:Class="menu.multiPlayer"
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:menu"
mc:Ignorable="d"
Title="Multi Player | Memory Game" Height="450" Width="800">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="1*" />
<RowDefinition Height="1*" />
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal" Grid.Column="0" Grid.Row="0">
<Label Content="Name of 1st Player:"/>
<TextBox />
<Label Content="Name of 2nd Player:"/>
<TextBox />
</StackPanel>
</Grid>
</Window>
提前感谢,德克