[英]C# WPF UserControls are not in the windows
MainWindow代码是这样的:
<Window x:Class="UserGUI.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:UserGUI"
mc:Ignorable="d"
Title="MainWindow" Height="657.278" Width="952.33" ResizeMode="CanMinimize">
<Canvas>
<ContentControl Name="mainContentControl" Grid.Column="0" Height="585" Width="934" Canvas.Top="31"/>
<ContentControl Name="upperMenu" Grid.Column="1" Height="31" Width="944"/>
</Canvas>
xaml是:
public MainWindow()
{
InitializeComponent();
mainContentControl.Content = new AdminMenu();
upperMenu.Content = new LoginScreen();
}
但是我在主窗口中看不到用户控件。似乎它们根本没有对齐
我究竟做错了什么? LoginScreen画布为:
<Canvas x:Name="loginCanvas" Background="BlanchedAlmond" Height="620" VerticalAlignment="Top" HorizontalAlignment="Left" Width="934">
并且userControl窗口本身的窗口是:
Height="630" Width="944">
希望我足够清楚
您的XAML中有一些奇怪的事情。 没有网格,也没有列,但是您有一些基于它的定位。 尝试这个:
<Window x:Class="UserGUI.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:local="clr-namespace:UserGUI"
Title="MainWindow" Height="657.278" Width="952.33" ResizeMode="CanMinimize">
<Canvas>
<ContentControl Name="mainContentControl" Height="585" Width="934" Canvas.Top="31" Canvas.Left="0"/>
<ContentControl Name="upperMenu" Canvas.Top="0" Canvas.Left="0" Height="31" Width="944"/>
</Canvas>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.