I want to rotate Image Control using LayoutTransform but the problem i am facing is that i can do this in XMAL but not code behind.
i am new to WPF
here is XMAL
`
<Image Grid.Column="1" Grid.Row="4" Height="155" HorizontalAlignment="Left"
Margin="103,0,0,0" Name="image1" Stretch="Fill" VerticalAlignment="Top" Width="139"
Source="/7SegmentLed;component/Images/Caster1.png" Grid.RowSpan="2" >
<Image.LayoutTransform>
<RotateTransform Angle="{Binding AngleSlider}" />
</Image.LayoutTransform>
</Image>
and CODE
double AngleSlider = 90.0;
image1.DataContext = AngleSlider;
i want to update it dynamically from the values i compute at back but the fact is that i donot want to change the image it is fixed and will not change
it would be great if anyone let me know what i am doing wrong
Your binding is a bit off; while you can set the
DataContextto a double, your binding is going to attempt to find a property calledAngleSlideron your double, which is obviously not there.So instead, create a class with a property of type
DoublecalledAngleSliderlike so:Create an instance of this class, and save it in a field on your Window, and then assign that instance to the
DataContext:Now, when necessary you can do:
And your image should rotate.