WPF XAML日期时间字符串的格式化
2021-01-21 01:15
标签:div 推荐 using -name com price ring dde 代码 XAML中的日期格式化跟程序代码中的格式化很类似,但有一些小小的不同: 鸣谢: WPF String.Format in XAML with the StringFormat attribute 达叔傻乐(darwin.zuo@163.com) WPF XAML日期时间字符串的格式化 标签:div 推荐 using -name com price ring dde 代码 原文地址:https://www.cnblogs.com/lonelyxmas/p/12114629.html对于某些控件我们可以使用ContentStringFormat
Label
Content="{Binding Path=BirthDate}"
ContentStringFormat="{}{0:dd MM YYYY HH:mm:ss}" />
Label
Content="{Binding Path=BirthDate}"
ContentStringFormat="{}{0:d}" />
Label
Content="{Binding Path=BirthDate}"
ContentStringFormat="{}{0:t}" />
Label
Content="{Binding Path=BirthDate}"
/>
对于很多控件我们可以在绑定时使用StringFormat
ListView.View>
GridView AllowsColumnReorder="True">
GridViewColumn x:Name="colBirthDate" Header="出生日期"
DisplayMemberBinding="{Binding Path=BirthDate, StringFormat=‘{}{0:t}‘}"
Width="Auto"/>
GridView>
ListView.View>
TextBlock Text="{Binding Path=BirthDate, StringFormat={}{0:MM/dd/yyyy}}" />
TextBlock Text="{Binding Path=BirthDate, StringFormat={}{0:MM/dd/yyyy hh:mm tt}}" />
TextBlock Text="{Binding Path=Price, StringFormat={}{0:C}}" />
TextBlock Text="{Binding Path=Price, StringFormat=价格:{0:C}}" />
Button Content="Delete Me">
Button.ToolTip>
ToolTip>
StackPanel Orientation="Horizontal">
TextBlock>
TextBlock.Text>
MultiBinding StringFormat="Delete {0} {1}">
Binding Path="FirstName" />
Binding Path="LastName" />
MultiBinding>
TextBlock.Text>
TextBlock>
XAML Using String Format
文章标题:WPF XAML日期时间字符串的格式化
文章链接:http://soscw.com/index.php/essay/44798.html