【问题标题】:Concatenate literals and staticresource string purely in xaml纯粹在 xaml 中连接文字和静态资源字符串
【发布时间】:2011-09-12 09:28:15
【问题描述】:

我试过这个:

Sets literally Show {Binding Source={StaticResource AppInfoer}, Path=Title}
<MenuItem Header="Show {Binding Source={StaticResource AppInfoer}, Path=Title}" 
Command="{StaticResource ShowWindowCommand}" CommandParameter="Open" />

鉴于Header="{Binding Source={StaticResource AppInfoer}, Path=Title}" 很好地解析为“主应用程序”,我怎么能成功

  • 添加文字字符串“Show”
  • {Binding Source={StaticResource AppInfoer}, Path=Title}的字符串输出

我希望没有额外的代码隐藏解决方案,该解决方案只涉及一两行 xaml

【问题讨论】:

    标签: c# wpf xaml binding


    【解决方案1】:

    您是否尝试过使用StringFormat

    {Binding Source={StaticResource AppInfoer}, Path=Title, StringFormat=Show {0}}
    

    【讨论】:

    • 谢谢,但是当我在 MenuItem 标头中复制您的代码时,它只显示“主应用程序”?即它没有预先设置“显示”..
    • 也许MenuItemHeader 不支持StringFormat?也没有运气with {}single straight quotes
    • 最后,让它与替代实现 internal class PrependConverter : IValueConverter { public object Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture) { return string.Format("Show {0}", value); } //... } 和 XAML &lt;tn:PrependConverter x:Key="PrependConverter"/&gt; 加上 &lt;MenuItem Header="{Binding Source={StaticResource AppInfoer}, Path=Title, Converter={StaticResource PrependConverter}}"&gt; 一起工作
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-05
    • 1970-01-01
    • 2016-05-11
    相关资源
    最近更新 更多