You could use IMultiValue
converter, this way you can pass in the Width
and the Precentage
so you can calculate the width of the column.
Example:
Converter:
public class PercentageConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (values[0] is double && values[1] is double)
{
return (((double)values[0]) / 100) * ((double)values[1]);
}
return values[0];
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
Xaml:
<Rectangle Width="auto" Fill="Green" Height="20" Grid.Row="0" Grid.Column="1">
<Rectangle.Width>
<MultiBinding Converter="{StaticResource PercentageConverter}">
<Binding Path="Width" />
<Binding Path="UtilPct" />
</MultiBinding>
</Rectangle.Width>
</Rectangle>