【问题标题】:C# WPF UserControls are not in the windowsC# WPF 用户控件不在窗口中
【发布时间】:2016-04-15 18:32:03
【问题描述】:

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">

希望我足够清楚

【问题讨论】:

  • 不,你不够清楚。什么是 AdminMenu 和 LoginScreen。它们位于何处。显示所有代码

标签: c# wpf xaml user-controls


【解决方案1】:

您的 XAML 中有一些奇怪的东西。没有 Grid 也没有列,但你有一些基于它的定位。试试这个:

<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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多