views:

610

answers:

1

I have a StackPanel with a list of custom user controlls that I would like to resize. I would like the user to be able to drag a slider and scale the control size up and down.

Is there a way to bind the control width to a slider value? Something similar to:

<MyControl Width="{Binding Path=SizeSlider.SelectedValue}"/>

Is this possible? Or should I just iterate through the controls and manually set the size whenever the slider value changes?

+1  A: 

You should be able to do this just fine by using

<MyControl Width="{Binding ElementName=SizeSlider, Path=Value}"/>

By only setting Path you assume that something named SizeSlider would exist in the current DataContext.

I've done this in code once and it worked:

var binding = new Binding("Value") { Source = slider };
BindingOperations.SetBinding(b, WidthProperty, binding);
BindingOperations.SetBinding(b, HeightProperty, binding);

So apparently

<MyControl Width="{Binding Source=SizeSlider, Path=Value}"/>

might be another way to do it.

Joey