我不知道为什么我无法将文本分配给标签,如果我使用文本框那么它就可以了...
我的xaml:
<Label Name="TimerLabel" Grid.Row="2" Grid.Column="0" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="1" />
xaml.cs:
TimerLabel.Text = "sadssa";
我相信我有正确的引用...我可以使用 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/