tags:

views:

62

answers:

1

I have a property:

public double S { get; set; }

and XAML:

<Canvas Name="MainCanvas">
    <Ellipse Canvas.Left="10" Canvas.Top="10" Height="10" Name="ellipse1" Stroke="Black" Width="10"/>
</Canvas>

How can I bind both Ellipse Width and Height properties and attached Canvas.Left and Top properties so that I can set values to be different fractions of S?

So Canvas.Left and Top could be 1/2f * S while width and height could be 3/4.

+1  A: 

Use a value converter in your binding to do the calculation for you.

<Ellipse Canvas.Left="{Binding Path=S,Converter=LeftConverter}" ... />

In the value converter, you would have:

public object Convert(object value, Type targetType, object paramenter, CultureInfo culture)
{
   double value = Double.Parse(value);
   return value * 0.5;
}

This code is untested but should get you started. Check out this sample here

benPearce