xaml - 向 {x :Bind} in XAML Universal Windows Platform 添加额外的字符串

标签 xaml windows-store-apps uwp

我是 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/

相关文章:

windows - Cordova - 是否可以在 config.xml 中配置 Windows 应用程序图标和启动屏幕?

c# - UWP 应用程序中应使用哪个命名空间类 HttpClient?

c# - 使用 Template10 的多个 View 而不总是显示主页?

c# - UWP XAML 弹出窗口不尊重垂直对齐?

c# - 如何显示 LongListSelector 的标题

c# - 将 Windows 应用商店应用程序连接到本地主机

javascript - 如何在 WinJS ListView 中手动触发 oniteminvoked

windows - 在 Windows Phone uWP 中使用 Gridview 时显示默认边框

c# - 如何定期制作动画?

c# - 如何在 Windows 10 通用应用程序中显示模态窗口?