var FullName = String.Format("{0} {1}", "FirstName", "LastName");
如何转换为TextBlock文本?
<TextBlock Text="" />
StringFormat
to the rescue:
<TextBlock>
<TextBlock.Text>
<MultiBinding StringFormat="{}{0} {1}">
<Binding Path="FirstName" />
<Binding Path="LastName" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
If you are wondering what the first {}
does, it is to prevent WPF from thinking the first {0}
is a MarkupExtension
.
无论TextBlock元素的标识符是什么,您都需要在代码中使用该标识符,然后执行以下操作:
TextBlockVariable.Text = FullName;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.