WPF 多重绑定字符串格式日期

发布于 2024-10-14 07:16:06 字数 463 浏览 1 评论 0原文

我正在尝试使用多重绑定来合并网格中的 2 个信息字段,多重绑定工作正常,但当我尝试开始格式化其中 1 个字段(此绑定中的日期)时,我遇到了问题。

这两个字段是用户首字母缩写,即 EGJ 和输入日期,希望实现类似于“EGJ - 01/01/2011”的组合字段

下面是我使用现有 XAML 的位置

<tk:DataGridTextColumn.Binding>
  <MultiBinding StringFormat=" {0} - {}{1:dd/MM/yyyy}">
    <Binding Path="UserInitials" />
    <Binding Path="EntryDate" />
  </MultiBinding>
</tk:DataGridTextColumn.Binding>   

非常感谢任何帮助或指示

I'm trying to combine 2 fields of information in my grid by using a Multibinding, the multibinding is working fine but I'm having problems when I try to start formating 1 of the fields which is a date in this binding.

The 2 fields are Users Initials i.e. EGJ and the entry date hoping to achieve a combined field looking like "EGJ - 01/01/2011"

Below is where I'm with my existing XAML

<tk:DataGridTextColumn.Binding>
  <MultiBinding StringFormat=" {0} - {}{1:dd/MM/yyyy}">
    <Binding Path="UserInitials" />
    <Binding Path="EntryDate" />
  </MultiBinding>
</tk:DataGridTextColumn.Binding>   

Any help or pointers are most appreciated

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

嗫嚅 2024-10-21 07:16:06

看不到树木的木材

只需移除空支架就解决了我的问题。

<tk:DataGridTextColumn.Binding>
  <MultiBinding StringFormat=" {0} - {1:dd/MM/yyyy}">
    <Binding Path="UserInitials" />
    <Binding Path="EntryDate" />
  </MultiBinding>
</tk:DataGridTextColumn.Binding>

感谢所有花时间查看的人。

Couldn't see the wood for the trees

Simply removing the empty braces solved my problem.

<tk:DataGridTextColumn.Binding>
  <MultiBinding StringFormat=" {0} - {1:dd/MM/yyyy}">
    <Binding Path="UserInitials" />
    <Binding Path="EntryDate" />
  </MultiBinding>
</tk:DataGridTextColumn.Binding>

Thanks to everyone who took the time to look.

孤千羽 2024-10-21 07:16:06

除非您打算在格式化值中包含前导空格,否则应使用此绑定:

<tk:DataGridTextColumn.Binding> 
  <MultiBinding StringFormat="{}{0} - {1:dd/MM/yyyy}"> 
    <Binding Path="UserInitials" />
    <Binding Path="EntryDate" />
  </MultiBinding>
</tk:DataGridTextColumn.Binding>

如果 StringFormat 以左大括号 { 开头,则 XAML 解析器要求您对其进行转义使用一对大括号{}。否则,解析器会感到困惑,因为标记扩展的语法中也使用了大括号。

有关详细信息,请参阅{}转义序列/标记扩展的 XAML 文档。

也许您最初已将转义序列正确放置在格式字符串中,并且移动的内容导致空大括号对出现在错误的位置?

Unless you intend to have a leading space in the formatted value you should use this binding instead:

<tk:DataGridTextColumn.Binding> 
  <MultiBinding StringFormat="{}{0} - {1:dd/MM/yyyy}"> 
    <Binding Path="UserInitials" />
    <Binding Path="EntryDate" />
  </MultiBinding>
</tk:DataGridTextColumn.Binding>

If the StringFormat starts with a left brace { the XAML parser require you to escape it using a pair of braces {}. Otherwise the parser gets confused because braces also are used in the syntax of markup extensions.

Details are found in the XAML documentation for {} Escape Sequence / Markup Extension.

Perhaps you had the escape sequence correctly placed in the format string initially and the moved things around resulting in the empty pair of braces at the wrong place?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文