内容简介:http://stackoverflow.com/questions/15520579/xaml-bind-to-static-method-with-parameters
我有一个静态类,如下所示:
public static class Lang
{
public static string GetString(string name)
{
//CODE
}
}
现在我想在xaml中访问这个静态函数作为绑定.
有没有这样一个例子:
<Label Content="{Binding Path="{x:static lang:Lang.GetString, Parameters={parameter1}}"/>
还是为每个可能的参数创建一个ObjectDataProvider?
希望有人能够帮助我.提前致谢!
我也得到这个需要.我使用转换器“解决了”(如建议 here ).
首先,创建一个返回转换字符串的转换器:
public class LanguageConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (parameter == null)
return string.Empty;
if (parameter is string)
return Resources.ResourceManager.GetString((string)parameter);
else
return string.Empty;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
然后将其用于XAML:
<Window.Resources>
<local:LanguageConverter x:Key="LangConverter" />
</Window.Resources>
<Label Content="{Binding Converter={StaticResource LangConverter},
ConverterParameter=ResourceKey}"/>
问候.
http://stackoverflow.com/questions/15520579/xaml-bind-to-static-method-with-parameters
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
我看电商2(双色)
黄若 / 电子工业出版社 / 2016-6 / 39.00元
《我看电商2》是行业畅销书《我看电商》的续集。 《我看电商》自出版以来,连续印刷14 次,受到业界人士和广大读者的高度好评。《我看电商2》承续作者一贯的风格,以行业观察、经验分享为出发点,重点分析了过去一年中国电商界的最新动态与趋势,包括双11点评、京东关闭拍拍、上市公司私有化等。 电子商务是我国近年来发展最快的新兴行业之一,作者作为这个行业的长老级领军人物,善于思考,长于实操。《我看......一起来看看 《我看电商2(双色)》 这本书的介绍吧!