<p>Anyone know if it's possible to databind the ScaleX and ScaleY of a render transform in Silverlight 2 Beta 2? Binding transforms is possible in WPF - But I'm getting an error when setting up my binding in Silverlight through XAML. Perhaps it's possible to do it through code?</p>

<pre><code>&lt;Image Height="60" HorizontalAlignment="Right" 
       Margin="0,122,11,0" VerticalAlignment="Top" Width="60" 
       Source="Images/Fish128x128.png" Stretch="Fill" 
       RenderTransformOrigin="0.5,0.5" x:Name="fishImage"&gt;
    &lt;Image.RenderTransform&gt;
         &lt;TransformGroup&gt;
             &lt;ScaleTransform ScaleX="1" ScaleY="1"/&gt;
             &lt;SkewTransform/&gt;
             &lt;RotateTransform/&gt;
             &lt;TranslateTransform/&gt;
         &lt;/TransformGroup&gt;
    &lt;/Image.RenderTransform&gt;
&lt;/Image&gt;
</code></pre>

<p>I want to bind the ScaleX and ScaleY of the ScaleTransform element.</p>

<p>I'm getting a runtime error when I try to bind against a double property on my data context: </p>

<pre><code>Message="AG_E_PARSER_BAD_PROPERTY_VALUE [Line: 1570 Position: 108]"
</code></pre>

<p>My binding looks like this:</p>

<pre><code>&lt;ScaleTransform ScaleX="{Binding Path=SelectedDive.Visibility}" 
                ScaleY="{Binding Path=SelectedDive.Visibility}"/&gt;
</code></pre>

<p>I have triple verified that the binding path is correct - I'm binding a slidebar against the same value and that works just fine...</p>

<p>Visibility is of type double and is a number between 0.0 and 30.0. I have a value converter that scales that number down to 0.5 and 1 - I want to scale the size of the fish depending on the clarity of the water. So I don't think it's a problem with the type I'm binding against...</p>

[{'answer_id': 27309, 'author': 'Matt Hamilton', 'author_id': 615, 'author_profile': 'https://Stackoverflow.com/users/615', 'pm_score': 1, 'selected': False, 'text': '<p>Is it a runtime error or compile-time, Jonas? Looking at the <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.scaletransform.scalex.aspx" rel="nofollow noreferrer">documentation</a>, ScaleX and ScaleY are dependency properties, so you should be able to write</p>\n\n<pre><code>&lt;ScaleTransform ScaleX="{Binding Foo}" ScaleY="{Binding Bar}" /&gt;\n</code></pre>\n\n<p>... where Foo and Bar are of the appropriate type.</p>\n\n<p>Edit: Of course, that\'s the WPF documentation. I suppose it\'s possible that they\'ve changed ScaleX and ScaleY to be standard properties rather than dependency properties in Silverlight. I\'d love to hear more about the error you\'re seeing.</p>\n'}, {'answer_id': 27337, 'author': 'Matt Hamilton', 'author_id': 615, 'author_profile': 'https://Stackoverflow.com/users/615', 'pm_score': 0, 'selected': False, 'text': '<p>Ah I think I see your problem. You\'re attempting to bind a property of type Visibility (SelectedDive.Visibility) to a property of type Double (ScaleTransform.ScaleX). WPF/Silverlight can\'t convert between those two types.</p>\n\n<p>What are you trying to accomplish? Maybe I can help you with the XAML. What is "SelectedDive" and what do you want to happen when its Visibility changes?</p>\n'}, {'answer_id': 27401, 'author': 'Matt Hamilton', 'author_id': 615, 'author_profile': 'https://Stackoverflow.com/users/615', 'pm_score': 0, 'selected': False, 'text': '<p>Sorry - was looking for the answer count to go up so I didn\'t realise you\'d edited the question with more information.</p>\n\n<p>OK, so Visibility is of type Double, so the binding should work in that regard.</p>\n\n<p>As a workaround, could you try binding your ScaleX and ScaleY values directly to the slider control that SelectedDive.Visibility is bound to? Something like:</p>\n\n<pre><code>&lt;ScaleTransform ScaleX="{Binding ElementName=slider1,Path=Value}" ... /&gt;\n</code></pre>\n\n<p>If that works then it\'ll at least get you going.</p>\n\n<p>Edit: Ah, I just remembered that I read once that Silverlight doesn\'t support the ElementName syntax in bindings, so that might not work.</p>\n'}, {'answer_id': 27413, 'author': 'Matt Hamilton', 'author_id': 615, 'author_profile': 'https://Stackoverflow.com/users/615', 'pm_score': 0, 'selected': False, 'text': '<p>Yeah maybe the embedded render transforms aren\'t inheriting the DataContext from the object they apply to. Can you force the DataContext into them? For example, give the transform a name:</p>\n\n<pre><code>&lt;ScaleTransform x:Name="myScaler" ... /&gt;\n</code></pre>\n\n<p>... and then in your code-behind:</p>\n\n<pre><code>myScaler.DataContext = fishImage.DataContext;\n</code></pre>\n\n<p>... so that the scaler definitely shares its DataContext with the Image.</p>\n'}, {'answer_id': 27424, 'author': 'Matt Hamilton', 'author_id': 615, 'author_profile': 'https://Stackoverflow.com/users/615', 'pm_score': 0, 'selected': False, 'text': '<p>Ok, is the Image itself picking up the DataContext properly?</p>\n\n<p>Try adding this:</p>\n\n<pre><code>&lt;Image Tooltip="{Binding SelectedDive.Visibility}" ... /&gt;\n</code></pre>\n\n<p>If that compiles and runs, hover over the image and see if it displays the right value.</p>\n'}, {'answer_id': 27478, 'author': 'Brian Leahy', 'author_id': 580, 'author_profile': 'https://Stackoverflow.com/users/580', 'pm_score': 2, 'selected': True, 'text': "<p>ScaleTransform doesn't have a data context so most likely the binding is looking for SelectedDive.Visibility off it's self and not finding it.  There is much in Silverlight xaml and databinding that is different from WPF... </p>\n\n<p>Anyway to solve this you will want to set up the binding in code**, or manually listen for the PropertyChanged event of your data object and set the Scale in code behind.</p>\n\n<p>I would choose the latter if you wanted to do an animation/storyboard for the scale change.</p>\n\n<p>** i need to check but you may not be able to bind to it. as i recall if the RenderTransform is not part of an animation it gets turned into a matrix transform and all bets are off.  </p>\n"}, {'answer_id': 27487, 'author': 'Jonas Follesø', 'author_id': 1199387, 'author_profile': 'https://Stackoverflow.com/users/1199387', 'pm_score': 0, 'selected': False, 'text': "<p>I was hoping to solve this through XAML, but turns out Brian's suggestion was the way to go. I used Matt's suggestion to give the scale transform a name, so that I can access it from code. Then I hooked the value changed event of the slider, and manually updates the ScaleX and ScaleY property. I kept my value converter to convert from the visibility range (0-30m) to scale (0.5 to 1). The code looks like this:</p>\n\n<pre><code>    private ScaleConverter converter;\n\n    public DiveLog()\n    {           \n        InitializeComponent();\n\n        converter = new ScaleConverter();\n        visibilitySlider.ValueChanged += new \n          RoutedPropertyChangedEventHandler&lt;double&gt;(visibilitySlider_ValueChanged);\n    }        \n\n    private void visibilitySlider_ValueChanged(object sender,   \n                                        RoutedPropertyChangedEventArgs&lt;double&gt; e)\n    {\n        fishScale.ScaleX = (double)converter.Convert(e.NewValue, \n                                   typeof(double), null, CultureInfo.CurrentCulture);\n        fishScale.ScaleY = fishScale.ScaleX;\n    }\n</code></pre>\n"}]
['https://Stackoverflow.com/questions/27303', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1199387/']