我正在編寫我的第一個Silverlight應用程序。我有一個具有兩個標籤的列的datagrid,對於標籤,我使用IValueConverter來有條件地格式化數據。將字段的值傳遞給Silverlight ConverterParameter
標籤的 「內容」 被設定爲這樣:
Content="{Binding HomeScore, Converter={StaticResource fmtshs}}"
和
Content="{Binding AwayScore, Converter={StaticResource fmtshs}}"
的轉換我的IValueConverter的方法是這樣的:
Public Function Convert(
ByVal value As Object,
ByVal targetType As System.Type,
ByVal parameter As Object,
ByVal culture As System.Globalization.CultureInfo) As Object
Implements System.Windows.Data.IValueConverter.Convert
Dim score As Long = value, other As Long = parameter
Return If(score < 0, "",
If(score - other > 5, (other + 5).ToString, score.ToString)
)
End Function
所以我想要做的就是在HomeScore的轉換器中,我想將AwayScore傳遞給ConverterParameter和AwayScore,我想將HomeScore傳遞給轉換器。在任何一個分數的轉換器中,我都需要能夠知道其他分數的值用於格式化目的。
但我找不出將ConverterParameter綁定到另一個字段的語法。
我已經試過如下:
Content="{Binding HomeScore, Converter={StaticResource fmtshs}, ConverterParameter=AwayScore}"
Content="{Binding HomeScore, Converter={StaticResource fmtshs}, ConverterParameter={AwayScore}}"
Content="{Binding HomeScore, Converter={StaticResource fmtshs}, ConverterParameter={Binding AwayScore}}"
但這些都不似乎工作。如何將字段值傳遞給ConverterParameter?
我曾嘗試單是有用的引號,但在轉換器中,它給了我一串'{綁定SomeOtherProperty}'。我錯過了什麼嗎? :(PS。我使用Silverlight 3 – 2010-07-16 01:31:12
看多路捆綁轉換器 http://stackoverflow.com/questions/377841/what-should-the-converter-parameter-be-for-this-binding – Rauld 2012-08-08 09:27:28