【发布时间】:2020-02-24 00:52:18
【问题描述】:
如果这个问题的答案很简单,我深表歉意,但我刚刚开始学习 UWP,真的无法自己找到解决方案。
我的主页中有一个名为ClockWidget 的UserControl 包含在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,它就“消失”了。
编辑
我添加了一些屏幕截图来帮助澄清问题。
如您所见,ClockWidget.xaml 本身似乎工作正常,文本显示。
但是,一旦我将其插入MainPage.xaml,它就不会出现。我在此屏幕截图中选择了ClockWidget,因此如您所见,大小仍然正确,但TextView 消失了。
【问题讨论】:
-
我创建了一个示例,但我无法重现您的问题,请尝试将
TextBlockForeground 属性设置为具有明显颜色。比如Foreground="OrangeRed" -
你的意思是在VisualStudio中看不到还是在运行中看不到?
-
@lindexi 我已经更新了问题,请查看
-
@nico-zhu-msft 这样做没有任何结果
-
文本是否显示在调试模型中?
标签: c# .net uwp user-controls uwp-xaml