I am having a problem with accessing Application Resources from a UserControl in my Silverlight application. Here is my 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>
I am getting an error on the line where I set the Header property of the tabPatients tab to the static resource My_Patients.
Here is my Application file:
<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开发者_如何学Python My Patients</System:String>
</Application.Resources>
</Application>
Can anyone tell me what is wrong?
From what I recall, this is a bug that's been around for some time--you can specify a string StaticResource
for a string property, but not for a content control's content (i.e. the TabItem
's Header
).
I may be wrong, but I think the following workaround may help:
Header="{Binding Source={StaticResource My_Patients}}"
At any rate, if your goal is to make your application localizable, I'd recommend reading Tim Heuer's blog post on the subject.
精彩评论