Right now I am "cheating" and using the following:
<Rectangle x:Name="rectangle" Stroke="SlateGray"
Width="{TemplateBinding ActualWidth}" Height="{TemplateBinding ActualHeight}"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
SizeChanged="rectangle_SizeChanged">
</Rectangle>
<x:Code>
<![CDATA[ private void rectangle_SizeChanged(object sender, SizeChangedEventArgs e)
{
Rectangle r = sender as Rectangle;
r.RadiusX = r.Height / 2;
r.RadiusY = r.Height / 2;
}
]]>
</x:Code>
This x:Code
works perfectly at run time and accomplishes what I want. but I really want it to change instantly on the Artboard
by doing something like:
<Rectangle x:Name="rectangle" Stroke="SlateGray"
Width="{TemplateBinding ActualWidth}" Height="{TemplateBinding ActualHeight}"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
RadiusX=".5*({TemplateBinding ActualHeight})"
RadiusY=".5*({TemplateBinding ActualHeight})">
</Rectangle>
But there is no way to include this .5*(...)
Is there another way to accomplish this?
To run code in a binding you use a converter class.
Then add the converter in a Resources section.
And add the coverter to your binding.
You can use the Blend binding windows to automatically add the resource and binding.