xaml - Silverlight Xaml 和资源中的 StringFormat

标签 xaml binding silverlight-4.0

我的资源文件中有格式字符串。我正在尝试使用 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>

最终结果如下所示:

Resource String Format

关于xaml - Silverlight Xaml 和资源中的 StringFormat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4025340/

相关文章:

c# - 在 WPF 中使用 ItemsControl 时正确对齐控件

c# - Ninject 绑定(bind),接口(interface)到接口(interface)

Silverlight 和代码覆盖率

silverlight - 银光鱼眼

WPF 绑定(bind) : Object in a object

c# - 透视表头样式

.net - 样式化 ContentControl

c# - ListView 更改 Metro Apps 中的文本大小

c++ - 具有基类型的派生类型的 Luabind 设置属性

Silverlight UI 文化