标签:binding 格式 lock 数据格式 code archive path 动态 tar
原文:WPF StringFormat 格式化文本WPF中,对数字/日期等的格式化,可参考此篇博客:https://www.cnblogs.com/zhengwen/archive/2010/06/19/1761036.html
例如:“已使用此软件 365 天!”,WPF中可如下处理
添加资源项:
1 <system:String x:Key="LangSource1">已使用此软件 {0} 天!</system:String>
StringFormat格式化:
1 <TextBlock Text="{Binding UsedDays,StringFormat={StaticResource LangSource1}}"/>
例如:“30/365”
1 <TextBlock> 2 <TextBlock.Text> 3 <MultiBinding StringFormat="{}{0}/{1}"> 4 <Binding Path="LearnedDays" FallbackValue="0" /> 5 <Binding Path="PlanningDays" FallbackValue="0" /> 6 </MultiBinding> 7 </TextBlock.Text> 8 </TextBlock>
例如:“已经学习30天,剩余计划学习天数365”
添加资源项:
1 <system:String x:Key="LangSource5">已经学习{0},剩余计划学习天数{1}</system:String>
WPF中stringFormat处理:
1 <TextBlock> 2 <TextBlock.Text> 3 <MultiBinding StringFormat="{StaticResource LangSource5}"> 4 <Binding Path="LearnedDays" FallbackValue="0" /> 5 <Binding Path="PlanningDays" FallbackValue="0" /> 6 </MultiBinding> 7 </TextBlock.Text> 8 </TextBlock>
例如:“学生张三的期末平均成绩为93.20分”
添加资源项:
1 <system:String x:Key="LangSource5">学生{0}的期末平均成绩为{1:N2}分</system:String>
WPF中stringFormat处理:
1 <TextBlock> 2 <TextBlock.Text> 3 <MultiBinding StringFormat="{StaticResource LangSource5}"> 4 <Binding Path="Name"/> 5 <Binding Path="Score"/> 6 </MultiBinding> 7 </TextBlock.Text> 8 </TextBlock>
标签:binding 格式 lock 数据格式 code archive path 动态 tar
原文地址:https://www.cnblogs.com/lonelyxmas/p/9716420.html