2015-10-15 28 views
0

我願做這樣的事情:使用轉換器進行多個綁定?

<Style TargetType="{x:Type Binding}"> 
    <Setter Property="Converter" Value="{StaticResource converter1}"/> 
</Style> 

這可能沒有什麼工作。那麼,如何告訴多個綁定使用哪個轉換器,而不必爲每個轉換器明確寫入?

+1

目前還不清楚你在問什麼。什麼不行?你期望什麼?發生了什麼? – venerik

回答

1

我很遺憾地說,但實際上有兩個原因,你不能這樣做。

<Style TargetType="{x:Type Binding}"> 
    <Setter Property="Converter" Value="{StaticResource converter1}"/> 
</Style> 

首先,你不能爲System.Windows.Data.Binding創建一個樣式,因爲它不符合造型的要求。 TargetType must derive from either FrameworkElement or FrameworkContentElement。唉,Binding inheritsBindingBase,然後MarkupExtension,然後Object,所以它不能被稱呼。

其次,Setter.Property is of type DependencyPropertyBinding.Converter不是一個依賴屬性,所以它不能有一個綁定的值。

所以,您將不得不在每個XAML {Binding}標記擴展的大括號內重複Converer={StaticResource converter1}