我的资源文件中有格式字符串。我正在尝试使用 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=。
是否可以从“嵌套绑定(bind)”访问资源?
最佳答案
Binding.StringFormat不是依赖属性,因此您不能设置与该属性的绑定(bind)。如果要为该属性分配值,则值必须是静态资源,如下所示:
<TextBlock Text="{Binding ProjectName, StringFormat={StaticResource ProjectNameFormat}}"/>
您应该像这样声明您的资源:
<UserControl.Resources>
<System:String x:Key="ProjectNameFormat">Project: {0}</System:String>
</UserControl.Resources>
最终结果如下所示:
关于xaml - Silverlight Xaml 和资源中的 StringFormat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4025340/