xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:WpfApplication1="clr-namespace:WpfApplication1"
x:Name="thisWindow" Title="WPF" Height="240" Width="280">
VerticalAlignment="Bottom"
Fill="Green"
Height="{Binding Path=Amount,Converter={StaticResource amountToHeightConverter}}"/>
ItemTemplate="{StaticResource dataItemtemplate}">
//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});
}
}
}