StringFormat第二個標簽中的正確語法是什么?
<Label Text="{Binding StringFormat='{0:F2}', Source={x:Static sys:Math.PI}}"/>
<Label>
<Label.Text>
<Binding StringFormat="{0:F2}" Source="{x:Static sys:Math.PI}"/>
</Label.Text>
</Label>

uj5u.com熱心網友回復:
這是一個 WPF 應用程式嗎?
在 WPF 中,Label 沒有 Text 屬性。有一個Content 屬性,它是 object 型別的。因此,對于此屬性,不使用到字串的轉換,因此不應用字串格式。
對于文本塊:
<TextBlock Text="{Binding StringFormat='{0:F2}', Source={x:Static sys:Math.PI}}"/>
<TextBlock Text="{Binding StringFormat={}{0:F2}, Source={x:Static sys:Math.PI}}"/>
<TextBlock>
<TextBlock.Text>
<Binding StringFormat="{}{0:F2}" Source="{x:Static sys:Math.PI}"/>
</TextBlock.Text>
</TextBlock>
<TextBlock>
<TextBlock.Text>
<Binding Source="{x:Static sys:Math.PI}">
<Binding.StringFormat>
<sys:String>{0:F2}</sys:String>
</Binding.StringFormat>
</Binding>
</TextBlock.Text>
</TextBlock>
<Binding>
<Binding.StringFormat>
<sys:String>{0:F2}</sys:String>
</Binding.StringFormat>
<Binding.Source>
<x:Static Member="sys:Math.PI"/>
</Binding.Source>
</Binding>
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/528302.html
標籤:wpfxmlxamarinxamarin.forms毛伊岛
上一篇:<x:Doublex:Key="fontsize">50</x:Double>可以轉換成純屬性語法還是純元素語法?
