【发布时间】:2020-04-02 16:00:46
【问题描述】:
我是 WPF 新手,我找不到在同一个主 WPF 应用程序上打开新 WPF 窗口的方法 我尝试了 Frame 方法,这是代码:-
<Window x:Class="WPF_FINAL.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:WPF_FINAL"
mc:Ignorable="d"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
TextElement.Foreground="{DynamicResource MaterialDesignBody}"
TextElement.FontWeight="Regular"
TextElement.FontSize="13"
TextOptions.TextFormattingMode="Ideal"
TextOptions.TextRenderingMode="Auto"
Background="{DynamicResource MaterialDesignPaper}"
Height="768"
Width="1366"
WindowState="Maximized"
Title="MainWindow">
<Grid Background="#dff9fb"
Margin="33,10,-33,-10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="20" />
<ColumnDefinition Width="13.5" />
<ColumnDefinition Width="152" />
<ColumnDefinition Width="auto"
MinWidth="335.5" />
<ColumnDefinition />
<ColumnDefinition Width="20" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="20" />
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
<RowDefinition Height="*" />
<RowDefinition Height="20" />
</Grid.RowDefinitions>
<Frame Margin="0,0,0.5,10"
Grid.ColumnSpan="5"
x:Name="main"
Grid.RowSpan="6">
</Frame>
</Grid>
</Window>
cs 代码
main.Content = new Window1();
但是当我运行时它给了我中断异常 我也试过导航服务,但我发现它只与页面相关联 任何建议如何做到这一点? 谢谢
【问题讨论】:
-
不,这不是办法艾哈迈德!为此,您应该使用
UserControl或Pages -
UserControl就像没有框架的window(默认情况下)可以,您可以像窗口一样实例化和使用它。但与 Window 不同,您可以在 Window 中嵌入userControl。希望它有所帮助:) -
还有一个 Popup 控件可以创建一个完全基于 UI 的短期对话框。 docs.microsoft.com/en-us/dotnet/framework/wpf/controls/…
标签: c# wpf visual-studio xaml navigationservice