c# - “标签不包含文本定义”

标签 c# xaml

我不知道为什么我无法将文本分配给标签,如果我使用文本框那么它就可以了...

我的xaml:

<Label Name="TimerLabel"  Grid.Row="2" Grid.Column="0" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="1" />

xaml.cs:

TimerLabel.Text = "sadssa";

/image/hpjY1.jpg

我相信我有正确的引用...我可以使用 Content="texthere"直接从 .xaml 将文本分配给标签,但我似乎无法通过代码分配文本。 (尝试了 TimerLabel.Content = "asds";但没有结果 /image/m7UyU.jpg )

最佳答案

分配标签的Content 属性。或者使用 TextBlock 代替。

TextBlock 与 WinForms 中的 Label 大致相同。

根据 MSDN :

The TextBlock control is the primary element for displaying text in Silverlight based applications.

Provides a lightweight control for displaying small amounts of text...

您可能需要考虑使用 TextBlock,具体取决于您使用它的方式。再次按照MSDN :

A Label control displays a caption, required field indicator, and validation error indicator to the user. It is typically used together with an input control, such as a TextBox. If you do not need to display required field or validation indicators, you can use the TextBlock control instead.

关于c# - “标签不包含文本定义”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39846942/

相关文章:

c# - 无法识别指定的类型

c# - 单击单个单元格时如何突出显示整个 DataGrid 行?

c# - Silverlight 按钮 Mouse Over 类似悬停效果

c# - 在一种形式中使用两个数据表

c# - 以 Json : 400 Bad request 发送图像

xaml - 如何在 Windows 8 中的 Metro 应用程序中创建菜单项

c# - uwp gridview 使用数据模板中的按钮删除项目

c# - 如何删除第一个 TabItem 和窗口边缘之间的这个小空间?

c# - 由于多个依赖项中的相同属性类型导致编译错误

c# - 尝试使用 Entity Framework Code First 更新数据库