嘿伙计们,我有这个转换器类:
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