Multiple bindings expressions in one statement
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>
精彩评论