【发布时间】:2012-11-21 09:29:24
【问题描述】:
大家好,我有这个转换器类:
public class InboxItemValueConverters : IValueConverter
{
public object Convert(object value, System.Type targetType,
object parameter, CultureInfo culture)
{
int urgency = (int)value;
Brush brush = new SolidColorBrush();
if (urgency == 0)
{
brush = new SolidColorBrush(Colors.Green); }
else if (urgency == 1)
{
brush = new SolidColorBrush(Colors.Yellow);
}
else if (urgency == 2)
{
brush = new SolidColorBrush(Colors.Red);
}
return brush;
}
public object ConvertBack(object value, System.Type targetType,
object parameter, CultureInfo culture)
{
return null;
}
public object ConvDateToShort(object value, System.Type targetType,
object parameter, CultureInfo culture)
{
DateTime DT = (DateTime)value;
return DT.ToShortDateString();
}
public object Convdateback(object value, System.Type targetType,
object parameter, CultureInfo culture)
{
return null;
}
}
这就是我第一次引用和使用它的方式:
<src:InboxItemValueConverters x:Key="converttocolor" />
<Canvas Background="{Binding Urgency, Converter={StaticResource converttocolor}}"
在课堂上没有,你们可以看到我有一个日期转换器吗?我将如何通过 xaml 获取该对象?想要在另一个控件中转换日期,来自同一类
新的xml:
Text="{Binding DocDate , Converter={StaticResource converttocolor}}"
提前致谢!
我正在使用visual studio 2012/windows phone 8/c#/silverlight
【问题讨论】:
标签: c# silverlight-5.0 winrt-xaml ivalueconverter