[英]How do i navigate from one Xaml file to another?
I am very new to XAML and WPF.I have a problem. 我对XAML和WPF非常陌生。
I have two files. 我有两个文件。 first.xaml and second.Xaml. first.xaml和second.Xaml。 There is a button in first.xaml, on click of which it should navigate to second.xaml.How do i achieve this. first.xaml中有一个按钮,单击后应导航至second.xaml。我该如何实现。
This is one way of organising the code: 这是组织代码的一种方式:
Your second.xaml
should contain your window definiton eg: 您的second.xaml
应该包含窗口定义,例如:
<Window x:Class="MediaCheckerWPF.AboutBox"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="About Media Checker" Height="300" Width="400" ResizeMode="NoResize"
Icon="/MediaCheckerWPF;component/Resources/checker.ico"
ShowInTaskbar="False">
<Grid>
...
</Grid>
</Window>
Your first.xaml
has the button eg: 您的first.xaml
具有按钮,例如:
<Button Height="23" HorizontalAlignment="Right" Name="aboutButton"
VerticalAlignment="Top" Width="23" Click="AboutButton_Click"
Content="{DynamicResource TInformationButton}"
ToolTip="{DynamicResource TInformationButtonTooltip}" Margin="0,0,8,0"/>
Then in the code behind: 然后在后面的代码中:
private void AboutButton_Click(object sender, RoutedEventArgs e)
{
var about = new AboutBox { Owner = this };
about.Initialise();
about.Show();
}
ChrisF's answer is a good way of popping up a new window in a Windows-style application, except you should not call Initialize that way (it should be called from the constructor). ChrisF的答案是在Windows风格的应用程序中弹出新窗口的好方法,除了您不应以这种方式调用Initialize(应从构造函数中调用)。
If you want web-style navigation instead, you should use the Page class instead of Window, along with NavigationService . 如果要使用Web样式的导航,则应使用Page类而不是Window以及NavigationService 。 This also allows your WPF application to run inside an actual web browser. 这也使您的WPF应用程序可以在实际的Web浏览器中运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.