[英]Can you call more than one converter on a property binding in xaml, and if so how
[英]Using a converter for more than one binding?
我想做這樣的事情:
<Style TargetType="{x:Type Binding}">
<Setter Property="Converter" Value="{StaticResource converter1}"/>
</Style>
那是行不通的。 那么,如何在不為每個轉換器明確編寫的情況下告訴多個綁定使用哪個轉換器呢?
我很抱歉地說,但是實際上有兩個原因不能執行此操作。
<Style TargetType="{x:Type Binding}">
<Setter Property="Converter" Value="{StaticResource converter1}"/>
</Style>
首先,您不能為System.Windows.Data.Binding
創建樣式,因為它不滿足樣式要求。 TargetType
必須從FrameworkElement
或FrameworkContentElement
派生 。 , Binding
繼承自BindingBase
, MarkupExtension
, Object
,因此無法設置樣式。
其次, Setter.Property
是DependencyProperty
類型 。 Binding.Converter
不是依賴項屬性,因此它根本不能綁定任何值。
因此 ,您將必須在每個XAML {Binding}
標記擴展的花括號內重復Converer={StaticResource converter1}
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.