'标签不包含文本定义' [英] 'Label does not contain a definition for text'
问题描述
我不知道为什么我无法将文本分配给标签,如果我使用的是文本框,那么它就可以了...
I dont know why I'm unable to assign text to a label, if I'm using a textbox then it does it fine...
我的 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";但没有结果 http://imgur.com/a/COPPu)
I have the right references I believe... I'm able to assign text to the label fine directly from the .xaml using Content="texthere" but I cant seem to assign text via the code. (Tried TimerLabel.Content = "asds"; but no result http://imgur.com/a/COPPu)
推荐答案
分配标签的 Content
属性.或者使用 TextBlock
代替.
Assign the Content
property of the label. Or use TextBlock
instead.
TextBlock
与 WinForms 中的 Label
大致相同.
TextBlock
is roughly the same as a Label
from WinForms.
根据 MSDN一个>:
TextBlock 控件是主要的用于显示文本的元素基于 Silverlight 的应用程序.
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:
You might want to consider a TextBlock depending on how your using it. Again per MSDN:
标签控件显示标题,必填字段指示符,以及验证错误指示符用户.它通常一起使用带有输入控件,例如文本框.如果不需要显示必填字段或验证指标,您可以使用 TextBlock改为控制.
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.
这篇关于'标签不包含文本定义'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!