UWP UserControl 大小正确但未呈现

UWP UserControl has correct size but isn't rendered

如果这个问题的答案很简单,我深表歉意,但我才刚刚开始学习 UWP,真的无法自己想出解决方案。

我有一个名为 ClockWidgetUserControl 包含在我主页的 Canvas 中。当 运行 应用程序时,控件(仅包含一个 TextBlock)具有正确的大小,但文本似乎没有被呈现。

MainPage.xaml

<Page
    x:Class="SmartMirror.IOT.MainPage"
    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:widgets="using:SmartMirror.IOT.Widgets"
    mc:Ignorable="d"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

    <Canvas x:Name="Canvas">
        <widgets:ClockWidget Width="500" Height="150" />
    </Canvas>
</Page>

ClockWidget.xaml

<UserControl
    x:Class="SmartMirror.IOT.Widgets.ClockWidget"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:SmartMirror.IOT.Widgets"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:widgetData="using:SmartMirror.Shared.Model.WidgetData"
    mc:Ignorable="d">
    <TextBlock Text="Hello World" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" />
</UserControl>

奇怪的是,在 ClockWidget.xaml 的预览中,一切都很好,但是一旦进入 MainPage.xaml,它 "disappears".


编辑

我添加了一些屏幕截图来帮助澄清问题。

如您所见,ClockWidget.xaml 本身似乎工作正常,显示了文本。

但是,一旦我将它插入 MainPage.xaml,它就不会出现。我在此屏幕截图中选择了 ClockWidget,因此如您所见,大小仍然正确,但 TextView 消失了。

所以,正如它所不得不的那样,它归结为一个令人难以置信的愚蠢的错误。在我的 ClockWidget.xaml.cs 代码隐藏中,我覆盖了默认构造函数,但不小心删除了 InitializeComponent() 调用。很明显,组件从未被初始化...

感谢大家的帮助和支持!