我是 XAML 的新手。我想向 x:bind 添加额外的字符串
我试过了
<AppBarToggleButton Icon="Phone" Label="E-Mail To {x:Bind e_mail}" />
<AppBarToggleButton Icon="Phone" Label="{"E-Mail To" + x:Bind e_mail}" />
我想收到“电子邮件至 email@email.com”
但没有成功。感谢帮助。
最佳答案
为此创建一个转换器:
public sealed class StringFormatConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
if (value == null)
return null;
if (parameter == null)
return value;
return string.Format(parameter.ToString(), value);
}
public object ConvertBack(object value, Type targetType, object parameter,
string language)
{
throw new NotImplementedException();
}
}
将此添加到您的页面/控件/应用程序资源:<converters:StringFormatConverter x:Key="StringFormatConverter" />
然后像这样使用它:<TextBlock Text="{x:Bind e_mail}"
Converter="{StaticResource StringFormatConverter}"
ConverterParameter="E-Mail To {0}!" />
关于xaml - 向 {x :Bind} in XAML Universal Windows Platform 添加额外的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35116861/