WPF SP1新功能—StringFormat

来源:互联网 发布:软件项目质量计划书 编辑:程序博客网 时间:2024/05/01 15:04

3.5SP1新功能之一是 stringformat.  这下面是一些示例代码。

<TextBox Text="{Binding Path=Double, StringFormat=F3}"/>

<TextBox Text="{Binding Path=Double, StringFormat=Amount: {0:C}}"/>

<TextBox Text="{Binding Path=Double, StringFormat=Amount: /{0:C/}}"/>

<TextBox>

  <TextBox.Text>

    <Binding Path="Double" StringFormat="{}{0:C}"/>

  </TextBox.Text>

</TextBox>

 

<TextBox>

  <TextBox.Text>

    <MultiBinding StringFormat="{}{0:F2} = {1:D}">

      <Binding Path="Double" />

      <Binding Path="Date"/>

    </MultiBinding>

  </TextBox.Text>

</TextBox>

<TextBox>

  <TextBox.Text>

    <Binding Path="Date" StringFormat="{}{0:MM/dd/yyyy}"/>

  </TextBox.Text>

</TextBox>

<ListBox Background="Beige" ItemStringFormat="F3">

  <sys:Double>1.11122</sys:Double>

  <sys:Double>2.11345</sys:Double>

</ListBox>

<GroupBox Background="AliceBlue" Content="{Binding Path=Double}" ContentStringFormat="F4"

          Header="{Binding Path=Double}" HeaderStringFormat="F5"/>

<Label Content="{Binding Path=Double}" ContentStringFormat="{}{0:E2}"/>

<GridView>

  <GridViewColumn Header="Date"

           DisplayMemberBinding="{Binding XPath=Date, StringFormat=D}" />

原创粉丝点击