WPF中,對數字/日期等的格式化,可參考此篇博客:https://www.cnblogs.com/zhengwen/archive/2010/06/19/1761036.htmlhtml
例如:學習
「已使用此軟件 365 天!」,WPF中可以下處理spa
添加資源項:code
1 <system:String x:Key="LangSource1">已使用此軟件 {0} 天!</system:String> orm
StringFormat格式化:htm
1 <TextBlock Text="{Binding UsedDays,StringFormat={StaticResource LangSource1}}"/> blog
文本:《365》資源
StringFormat格式化:get
<TextBlock Text="{Binding UsedDays,StringFormat=《{0}》}" Foreground="#018000"/>
其它案例:博客
1 <TextBox Text="{Binding Value, StringFormat={}{0:0000.0}}" /> // 0123.4 2 <TextBox Text="{Binding Value, StringFormat={}{0:####.#}}" /> // 123.4
例如:「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>
1 <TextBox.Text> 2 <MultiBinding StringFormat="姓名:{0}	{1}"> 3 <Binding Path="FristName" /> 4 <Binding Path="LastName" /> 5 </MultiBinding> 6 </TextBox.Text>
常見的特殊字符:
小於號(<) <
大於號(>) >
&符號(&) &
引號(") "
單引號(') '
回車 
換行 

Tab 	
空格  
例如:「學生張三的期末平均成績爲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>