WPF C#在此处更改代码中的标签内容不会';不反映
我在XAML中有一个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端设置内容,它将显示。但是,当我尝试在代码隐藏中设置内容时,它不会显示如下所示:
我的代码:
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标记。。??