gpt4 book ai didi

c# - WPF使用主窗口中的 View

转载 作者:行者123 更新时间:2023-12-03 10:52:23 26 4
gpt4 key购买 nike

我正在尝试在我的主窗口内部使用一个 View 。因此,我在项目的view文件夹内创建了view,然后尝试在主窗口中使用它。但是我得到运行时错误。有人可以帮忙吗?

XAML主窗口

<Window x:Class="DataRetrieval.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:prism="http://www.codeplex.com/prism"
xmlns:views="clr-namespace:DataRetrieval.Views"
Title="MainWindow" Height="350" Width="525">
<TabControl Name="TabControl1" >
<TabControl.ItemContainerStyle>
<Style TargetType="{x:Type TabItem}">
<Setter Property="Visibility" Value="Collapsed"/>
</Style>
</TabControl.ItemContainerStyle>
<TabItem Header="General">
<views:Login></views:Login>
</TabItem>

</TabControl>
</Window>

XAML View :
<Window x:Class="DataRetrieval.Views.Login"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Login" Height="300" Width="300">
<Grid>
<Grid.ColumnDefinitions>

<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>


</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0">
<Label Content="User Name:" Width="Auto"/>
<Label Content="Password:" Width="Auto"/>

</StackPanel>
<StackPanel Grid.Column="1">
<TextBox Grid.Column="1" Name="Username" Text="" VerticalAlignment="Top" Width="Auto"/>
<PasswordBox Grid.Column="1" Name="Password" VerticalAlignment="Top" Width="Auto"/>

</StackPanel>

</Grid>
</Window>

但是,当我运行应用程序时,我的主窗口xaml代码上出现运行时错误:
A first chance exception of type 'System.Windows.Markup.XamlParseException' occurred in PresentationFramework.dll

Additional information: 'Set property 'System.Windows.Controls.ContentControl.Content' threw an exception.' Line number '14' and line position '14'.

最佳答案

您不能将Window嵌套在另一个Window中。您可以将Grid直接放在Window中,也可以创建UserControl

关于c# - WPF使用主窗口中的 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33039964/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com