![](/img/trans.png)
[英]How can I change (i.e. toggle) the bound, StringFormat property of a WPF control?
[英]WPF - Can StringFormat be bound to a property?
給定一個WPF文本框,作為示例:
<TextBox Text="{Binding Path=blahProperty, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, StringFormat=\{0:yyyy.MM.dd HH:mm:ss\}}"/>
StringFormat我可以在那里綁定到底層屬性字符串嗎? - 即“yyyy.MM.dd HH:mm:ss”是否可以由View(或ViewModel)上的屬性提供,而不是在xaml中進行硬編碼?
不,無法在Binding
的StringFormat
屬性上設置{Binding}
,因為StringFormat
不是依賴項屬性。
您只能綁定到DependencyProperty
的DependencyObject
,即綁定的target屬性必須是依賴屬性。
您可以將其設置為靜態屬性的值,但:
StringFormat={x:Static local:MainWindow.StaticProperty}}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.