【发布时间】:2014-03-13 22:53:56
【问题描述】:
我正在尝试根据绑定值更改 ListBox 中的数据绑定 TextBlock 的前景色。
我的代码如下:xaml
<Grid.Resources>
<converters:ColorConverter x:Key="ColorConverter"/>
</Grid.Resources>
<ListBox>
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Name="TitleText">
<Run Foreground="{Binding Type, Converter={StaticResource ColorConverter}}" Text="₹" />
</TextBlock>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
ColorConverter 类:
public class ColorConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value != null)
{
String Value = (String)value;
if (Value.Equals("Credit"))
return Colors.Green;
else
return Colors.Red;
}
return null;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
当我运行代码时,没有错误,但颜色不会改变。
【问题讨论】:
标签: c# data-binding windows-phone-8 listbox foreground