Mega Code Archive
Use Data Triggers to Change the Appearance of Bound Data
//File:Window.xaml.cs
using System;
using System.Windows.Data;
using System.Globalization;
using System.Collections.ObjectModel;
namespace WpfApplication1
{
[ValueConversion(typeof (double), typeof (double))]
public class AmountToHeightConverter : IValueConverter
{
public Object Convert(Object value,Type targetType,Object parameter,CultureInfo culture)
{
double amount = System.Convert.ToDouble(value);
if(amount < 0)
amount = 0;
return amount;
}
public object ConvertBack(object value,Type targetType,object parameter,CultureInfo culture)
{
throw new NotImplementedException();
}
}
public class DataItem
{
public double Amount
{
get;
set;
}
public bool IsPositive
{
get
{
return Amount >= 0;
}
}
}
public class DataItems : Collection
{
public DataItems()
{
this.Add(new DataItem(){Amount=5});
this.Add(new DataItem(){Amount=8});
this.Add(new DataItem(){Amount=-5});
this.Add(new DataItem(){Amount=2});
this.Add(new DataItem(){Amount=-5});
this.Add(new DataItem(){Amount=-5});
}
}
}