【问题标题】:Syntax error binding to a static resource in Silverlight在 Silverlight 中绑定到静态资源的语法错误
【发布时间】:2010-02-17 17:49:53
【问题描述】:

我在从 Silverlight 应用程序中的 UserControl 访问应用程序资源时遇到问题。这是我的用户控件:

<UserControl x:Class="MyApp.MainControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:basics="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls" >
    <basics:TabControl TabStripPlacement="Left">
        <basics:TabItem Name="tabHome" Header="Home"></basics:TabItem>
        <basics:TabItem Name="tabPatients" Header="{StaticResource My_Patients}"></basics:TabItem>
        <basics:TabItem Name="tabOrganization" Header="My Organization"></basics:TabItem>
    </basics:TabControl>
</UserControl>

我在将 tabPatients 选项卡的 Header 属性设置为静态资源 My_Patients 的那一行出现错误。

这是我的申请文件:

<Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:System="clr-namespace:System;assembly=mscorlib" 
             x:Class="MyApp.App">
    <Application.Resources>
        <System:String x:Key="My_Patients">All My Patients</System:String>
    </Application.Resources>
</Application>

谁能告诉我怎么回事?

【问题讨论】:

  • 看不出有什么问题,在我的机器上运行良好。

标签: silverlight data-binding


【解决方案1】:

据我回忆,这是一个已经存在一段时间的错误——您可以为字符串属性指定字符串 StaticResource,但不能为内容控件的内容(即 TabItem 的 @987654324 @)。

我可能错了,但我认为以下解决方法可能会有所帮助:

Header="{Binding Source={StaticResource My_Patients}}"

无论如何,如果您的目标是使您的应用程序可本地化,我建议您阅读Tim Heuer's blog post on the subject

【讨论】:

  • 我无法重现该问题,但仔细想想我确实安装了 SL4。
  • 这个问题在 SL3 中肯定仍然存在——我还没有在 4 中尝试过。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-06-15
  • 1970-01-01
  • 1970-01-01
  • 2011-12-30
  • 1970-01-01
相关资源
最近更新 更多