一个窗口有标题栏(包括最小化/最大化/关闭按钮等),可以用来承载 XAML 元素,例如用户控件。
当然,你并不一定要在应用程序中只使用一个窗口,但有些应用程序会选择这种模式(一个窗口,承载多个用户控件)。
当你创建一个新的 WPF 应用程序时,默认情况下你的应用程序会像这样在 App.xaml 中进行配置:
<Application x:Class="WpfApplication1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml">
<Application.Resources>
</Application.Resources>
</Application>
StartupUri
属性告诉应用程序首先打开哪个窗口(如果您希望可以进行配置)。
如果您想要将窗口逻辑上分割成多个部分,并且不希望在一个文件中使用过多的XAML,则可以尝试以下方法:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApplication1"
Title="Window1" Height="300" Width="300">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="50" />
<RowDefinition />
</Grid.RowDefinitions>
<local:HeaderUserControl Grid.Row="0" />
<local:MainSectionUserControl Grid.Row="1" />
</Grid>
</Window>
其中HeaderUserControl
和MainSectionUserControl
是UserControls,封装了窗口的相关方面。
如果要显示另一个窗口,可以在代码中调用新窗口实例上的Show
或ShowDialog
方法...
此外 - 是的,页面是WPF浏览器应用程序的一部分,旨在在Internet Explorer中查看。