开发者

Multiple bindings expressions in one statement

开发者 https://www.devze.com 2022-12-27 21:21 出处:网络
Does WPF support multiple binding expressions in one statement? Something along the lines of the following:

Does WPF support multiple binding expressions in one statement? Something along the lines of the following:

 <TextBlock Text="{Binding Pat开发者_如何学JAVAh=OrderID} shipped on {Binding Path=OrderDate}"/>

I'm guessing that it does but I think I just don't have the correct syntax.


You have to use a MultiBinding with the StringFormat feature. Look at the docs for more info

<TextBox>
  <TextBox.Text>
    <MultiBinding StringFormat="{}{0} shipped on {1:D}">
      <Binding Path="OrderID" />
      <Binding Path="OrderDate"/>
    </MultiBinding>
  </TextBox.Text>
</TextBox>

To add support for forrmating specific sections of the textblock, use Inlines like so.

<Textblock>
   <Run FontWeight="Bold" Text="{Binding OrderID}"/>
   <Run Text="shipped on "/>
   <Run FontStyle="Italic" Text="{Binding OrderDate}"/>
</Textblock>
0

精彩评论

暂无评论...
验证码 换一张
取 消