I have a Label
here in XAML. If I set the content in the XAML side, it will display. But when I try to set the content in code behind, it doesn't display as it shows:
My code:
if (Application.Current.Resources["Values"] != null)
{
string score = Application.Current.Resources["Values"].ToString();
labelscore.Content = score;
}
I have checked the vale of the resource, the value is there but I can't display it.
My XAML side:
<Label Height="30" Width="100" Name="labelscore" FontWeight="Bold" FontSize="15" />
Try temporarily changing your line of code to
labelscore.Content = "TEST STRING";
and comment out the following line
if (Application.Current.Resources["Values"] != null)
If the Label
displays the text, then your Resources
are the problem.
Alternatively, try binding the value from your code behind to the Label
. This is generally the preferred method when using WPF.
<Label Height="30" Width="100" Binding="{Binding Values}" ... />
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.