我的资源文件中有格式字符串.我试图使用FormatString从TextBlock的Text属性访问这些
Text="{Binding Path=Project.Name,StringFormat={Binding Path=WkStrings.DisplayProjectName,Source={StaticResource ResourceWrapper}}}"
我收到以下错误:
Provide value on 'System.Windows.Data.Binding' threw an exception
错误指向Text =.
是否可以从“嵌套绑定”访问资源?
解决方法
Binding.StringFormat不是依赖项属性,因此您无法设置对此属性的绑定.如果要为该属性赋值,则您的值必须是静态资源,如下所示:
<TextBlock Text="{Binding ProjectName,StringFormat={StaticResource ProjectNameFormat}}"/>
您应该声明您的资源:
<UserControl.Resources> <System:String x:Key="ProjectNameFormat">Project: {0}</System:String> </UserControl.Resources>
最终结果如下: