如何在 XAML 元素中使用 StringFormat? [英] How to use StringFormat in XAML elements?
本文介绍了如何在 XAML 元素中使用 StringFormat?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我深入了解绑定到订单的元素的 XAML 堆栈.
I'm deep in a XAML stack of elements binding to orders.
订单日期显示为例如12/31/2008 12:00:00 AM".
The order date displays as e.g. "12/31/2008 12:00:00 AM".
我希望它显示为例如31.12.2008".
我该怎么做?我看过其他stackoverflow问题提到 StringFormat,但他们以我无法工作的方式使用多重绑定.
How can I do this? I have seen other stackoverflow questions mention StringFormat but they use multibinding in ways that I can't get to work.
这是我想要的那种语法(这是伪代码),只需在需要的地方指定 StringFormat,这可能以某种方式实现吗?
Here is the kind of syntax I would like (this is pseudocode), simply specifying StringFormat where you need it, is this possible somehow?
<StackPanel>
<ListView ItemsSource="{Binding Orders}">
<ListView.View>
<GridView>
<GridViewColumn
Header="Order ID"
DisplayMemberBinding="{Binding Path=OrderID}"
StringFormat="{}{1:dd.MM.yyyy}"/>
<GridViewColumn
Header="Order Date"
DisplayMemberBinding="{Binding Path=OrderDate}"/>
</GridView>
</ListView.View>
</ListView>
</StackPanel>
推荐答案
我还没有测试过,但我认为这应该可行:
I haven't tested it, but I think this should work:
<GridViewColumn
Header="Order Date"
DisplayMemberBinding=
"{Binding Path=OrderDate, StringFormat='{}{0:dd.MM.yyyy}'}"/>
这篇关于如何在 XAML 元素中使用 StringFormat?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文