Silverlight Xaml和资源中的StringFormat

前端之家收集整理的这篇文章主要介绍了Silverlight Xaml和资源中的StringFormat前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我的资源文件中有格式字符串.我试图使用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>

最终结果如下:

猜你在找的Silverlight相关文章