Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
WPF C#在此处更改代码中的标签内容不会';不反映_C#_Wpf_Label - Fatal编程技术网

WPF C#在此处更改代码中的标签内容不会';不反映

WPF C#在此处更改代码中的标签内容不会';不反映,c#,wpf,label,C#,Wpf,Label,我在XAML中有一个标签。如果我在XAML端设置内容,它将显示。但是,当我尝试在代码隐藏中设置内容时,它不会显示如下所示: 我的代码: if (Application.Current.Resources["Values"] != null) { string score = Application.Current.Resources["Values"].ToString(); labelscore.Content = score; } 我已经检查了资源的值

我在XAML中有一个
标签
。如果我在XAML端设置内容,它将显示。但是,当我尝试在代码隐藏中设置内容时,它不会显示如下所示:

我的代码:

if (Application.Current.Resources["Values"] != null)
{
    string score = Application.Current.Resources["Values"].ToString();
    labelscore.Content = score;           
}
我已经检查了资源的值,该值在那里,但我无法显示它

我的XAML方面:

<Label Height="30" Width="100" Name="labelscore" FontWeight="Bold" FontSize="15" />

尝试暂时将代码行更改为

labelscore.Content = "TEST STRING";
并注释掉下面一行

if (Application.Current.Resources["Values"] != null)
如果
标签
显示文本,则您的
资源
就是问题所在

或者,尝试将代码后面的值绑定到
标签
。这通常是使用WPF时的首选方法

<Label Height="30" Width="100" Binding="{Binding Values}" ... />


您是否尝试在
labelscore.Content=score上设置断点在你的代码隐藏中,以确保它确实被调用?我认为你的问题在于IF。您需要按照Chris的建议设置断点并进行检查。您是否在应用程序中定义了此资源。App.xaml内的Resources标记。。??