views:

250

answers:

1

I've got a bunch of ContentControls with a DataTemplate like so:

    <DataTemplate>         
        <Canvas>
            <Canvas.RenderTransform>
                <TransformGroup>
                    <ScaleTransform ScaleX="1.0" ScaleY="1.0"/>
                </TransformGroup>
            </Canvas.RenderTransform>
        </Canvas>
    </DataTemplate>

...and I want to change their scales dynamically. I'm new to .NET, so please forgive. I tried to use this technique:

http://msdn.microsoft.com/en-us/library/bb613579.aspx

...but DataTemplates don't appear to have FindName in Silverlight. I then tried binding the Scales like so:

<ScaleTransform ScaleX="{Binding Scale}" ScaleY="{Binding Scale}"/>

...but got a XAML error when I ran.

Am I barking up the wrong tree? I figure this must be possible somehow.

Thank you.

A: 

Assuming you don't want to animate the scale, simply include a Scale property in your view model. You cannot access an ancestors DataContext from inside a DataTemplate (WPF supports this, however).

Instead of setting the DataContext of your DataTemplate to your entity, create a wrapper class (ViewModel) that also includes a (INotifyPropertyChanged-firing) Scale property. Now your ContentControl can bind to the Scale property of your view model.

Richard Szalay
Thanks for the help!
Ian Gilman
You're welcome!
Richard Szalay