Pass value of a field to Silverlight ConverterParameter
Posted
by eidylon
on Stack Overflow
See other posts from Stack Overflow
or by eidylon
Published on 2009-08-28T05:24:15Z
Indexed on
2010/06/12
14:33 UTC
Read the original article
Hit count: 987
Hi all, I'm writing my very first Silverlight app. I have a datagrid with a column that has two labels, for the labels, i am using an IValueConverter to conditionally format the data.
The label's "Content" is set as such:
Content="{Binding HomeScore, Converter={StaticResource fmtshs}}"
and
Content="{Binding AwayScore, Converter={StaticResource fmtshs}}"
The Convert method of my IValueConverter is such:
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
So what i want to do is in the converter for HomeScore, i want to pass AwayScore to the ConverterParameter, and for AwayScore i want to pass the HomeScore to the converter. In the converter for either score i need to be able to know the value of the other score for formatting purposes.
But i cannot figure out the syntax for binding the ConverterParameter to another field.
I've tried the following:
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}}"
But none of those seem to work. How do i pass a field value to the ConverterParameter?
© Stack Overflow or respective owner