Click here to Skip to main content
15,885,141 members
Please Sign up or sign in to vote.
1.44/5 (2 votes)
See more:
hi

i have creted an image in wpf i want to rotate that WPF image in my winform application on changing the vlaue of numerical updown counter with 0dgree to 180dgree rotation ..?
Posted
Comments
Francisco T. Chavez 15-Nov-13 4:07am    
Have you looked into render transformations?
rahuls1 15-Nov-13 4:13am    
i am new to this please halp me out on this..
Francisco T. Chavez 15-Nov-13 4:24am    
If I had to guess, I would say that your best bet would be to bind the RenderTransform property of the Image instance to the Value property of the NumericalUpDown instance. I would also create a converte (for that binding) that creates an instance of the RotateTransform class to be used by the Image.
rahuls1 15-Nov-13 4:25am    
please provide the code as i am neew to this..
Leung Yat Chun 17-Nov-13 4:22am    
Hello, this is for WPF only, I don't know how to hook it to WinForms.

<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<DockPanel>
<Slider DockPanel.Dock="Bottom" Height="20" Minimum="0" Maximum="3600" x:Name="slider" />
<TextBlock Text="Z" FontSize="50" HorizontalAlignment="Center" VerticalAlignment="Center" TextAlignment="Center">
<TextBlock.LayoutTransform>
<RotateTransform CenterX="0.5" CenterY="0.5" Angle="{Binding Value, ElementName=slider}" />
</TextBlock.LayoutTransform>
</TextBlock>
</DockPanel>
</Page>

It uses LayoutTransform, in some case you can should use RenderTransform. As the name suggested LayoutTransform update it's layout in it's parent container as well, which means if you have a ScaleTransForm (change size of your control) with ScaleX and ScaleY set to 20, the panel grow because of that. RenderTransform doesn't update the layout. If you search LayoutTransform vs RenderTransform, you can find some useful articles.

Keep in mind that this is a guess, but I would say that the easiest way to do this might be applying a RotateTransform to the Image's RenderTransform property. RenderTransform is a DependencyProperty so you should be able to bind it to the Value property of the NumericUpDown. Yet, you are going to need an IValueConverter that transforms the value from the NumericUpDown into a RotateTransform. The code for the IValueConverter will look something like this:

C#
public class RotationsTransformConverter 
    : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        double angle;
        try
        {
            angle = (double) value;
        }
        catch
        {
            angle = 0.0;
        }
        RotateTransform transformation = new RotateTransform(angle);

        return transformation;
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}


Once you have your converter, you are going to have to instantiate it somewhere. I would advise setting it as a resource.

XML
<local:RotationsTransformConverter x:key="MyConverter"/>


Once the converter is up and ready to go, you create a binding from the Image's RenderTransform property to the NumericUpDown's Value property. In the Binding's Converter property, you will reference the converter as a StaticResource. That binding will look something like this:

XML
<Image RenderTransform="{Binding Path=, Mode=OneWay, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource MyConverter}}/>


If you look closely at the binding, you will notice that I left the path blank. I don't know what the path from the Image to the NumericUpDown is, so I'm going to let you fill that part out.
 
Share this answer
 
v4
You may assign a RotateTransform to the RenderTransform property of your Thumbs and modify the Angle of the RotateTransform in an event handler:

<thumb canvas.left="52" canvas.top="7" rendertransformorigin="0.5,0.5"> DragDelta="Thumb_DragDelta" MouseDoubleClick="Thumb_MouseDoubleClick">
<thumb.rendertransform> <rotatetransform>
<thumb.template> ...
The event handler may look like this:

private void Thumb_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
var thumb = e.Source as UIElement;
var transform = thumb.RenderTransform as RotateTransform;
transform.Angle += 90;
}

You should however change the large Margin values on your Thumbs, as they affect the rotation center.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900