资源文件
使用resourceManager类编辑调用资源调用函数
public static class Strings
{
public static ResourceManager resource = new ResourceManager ( "VD.Language.StringResource" , typeof ( Strings) . Assembly) ;
public static CultureInfo CultureInfo { get ; set ; }
public static string GetString ( string name)
{
return resource. GetString ( name, CultureInfo) ;
}
}
创建继承MarkupExtension的类,以用户xaml文件调用
[ MarkupExtensionReturnType ( typeof ( BindingExpression) ) ]
public class StringResourceExtension : MarkupExtension
{
[ ConstructorArgument ( "key" ) ]
public string Key
{
get ;
set ;
}
public string Value{ get = > Strings. GetString ( Key) ; }
public StringResourceExtension ( string key)
: this ( )
{
Key = key;
}
public StringResourceExtension ( )
{
}
public override object ProvideValue ( IServiceProvider serviceProvider)
{
Binding binding = new Binding ( "Value" ) { Source = this , Mode = BindingMode. OneWay } ;
return binding. ProvideValue ( serviceProvider) ;
}
}
XAML中对资源进行调用
xmlns: res = "clr-namespace:VD.Language"
< Label Content= "{res:StringResource AssayItem}" VerticalAlignment= "Center" Height= "28" HorizontalContentAlignment= "Center" VerticalContentAlignment= "Center" Foreground= "White" FontFamily= "Microsoft YaHei UI" FontWeight= "Bold" Margin= "0" >
< Label. Background>
< SolidColorBrush Color= "DarkGray" Opacity= "1" / >
< / Label. Background>
< / Label>