【发布时间】:2012-12-06 14:02:28
【问题描述】:
大家好,我有这个转换器:
public class BudgetIndicatorConverter :IValueConverter
{
public object Convert(object value, System.Type targetType,
object parameter, CultureInfo culture)
{
string Indicator = (string)value;
Brush _brush = new SolidColorBrush();
if (Indicator == "Green")
{
_brush = new SolidColorBrush(Colors.Green);
}
else if (Indicator == "Red")
{
_brush = new SolidColorBrush(Colors.Red);
}
return _brush;
}
public object ConvertBack(object value, System.Type targetType,
object parameter, CultureInfo culture)
{
return null;
}
}
这是我在 Xaml 中的绑定:
<TextBlock TextWrapping="Wrap" Margin="260,120,0,70" FontSize="{StaticResource PhoneFontSizeNormal}" Foreground="{Binding Data[0].BudgetIndicator, Converter={StaticResource budgetcolor}}" FontFamily="{StaticResource PhoneFontFamilyBold}" Text="{Binding Data[0].TOTAL, Converter={StaticResource convertcurrency}}" TextAlignment="Right"/>
现在当我运行它时,文本块现在什么都不显示?我想知道我是否可以在同一个控件上绑定 2 个属性。 就像您在文本属性中看到的那样,我将货币与转换器绑定并且它起作用了。
可能是我对“预算指标”的绑定无法发送正确的值吗?
我想要做的是,一旦显示货币,它应该将总数显示为绿色或红色,意味着在预算中还是超出预算?
任何提示或链接将不胜感激
使用visual studio 2012/c#/silverlight 5/windows phone8
如果需要更多内容来完成答案,请告诉我!
提前致谢!
【问题讨论】:
-
如果您没有设置转换器,绑定是否有效?
标签: silverlight windows-phone-8 ivalueconverter