Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi I need rotate my axis labes in CODE BEHIND.

My code:
C#
Style labelStyle = new Style(typeof(AxisLabel));
var setter = new Setter(AxisLabel.RenderTransformProperty, new RotateTransform() { Angle = -60, CenterX = 40, CenterY = 30 });
labelStyle.Setters.Add(setter);


And it look like on this pick :
Pic

The problem is, that it rotate text on some coordinates and it rly sux.

Can someone help me to fix it ? I need to rotate labels and it must end or start on the same points near axis X.

Thanks



EDIT:
I edit my code like this :
C#
var setter2 = new Setter(AxisLabel.RenderTransformOriginProperty, "1,0");
var setter = new Setter(AxisLabel.RenderTransformProperty, new RotateTransform() { Angle = 270 });

But that b..ch still remember his auto making position for fit the names (1. up, 2. down, 3. up,...)
Pic2

EDIT2:
i try this :
C#
var setter = new Setter(AxisLabel.RenderTransformProperty, new RotateTransform() { Angle = -60, CenterX = (double)GetValue(AxisLabel.ActualHeightProperty) / 2, CenterY = (double)GetValue(AxisLabel.ActualWidthProperty) /2});

but actual H/W is always H/W of whole graph not each label in cathegory axis :/

I am only one who try rotate axis in code ???
Posted
Updated 29-Feb-12 22:54pm
v7
Comments
Wendelius 3-Jan-12 8:59am    
Avoid using extensive bolding and text speak.
Amir Mahfoozi 3-Jan-12 9:45am    
Have you tried to do it with MS Blend ? It helps a lot in these types of problems.

1 solution

Herez the code:

C#
var labelStyle = new Style(typeof(AxisLabel));
var rotate = new Setter(RotateTransform.AngleProperty, 270);
var setter = new Setter(AxisLabel.RenderTransformProperty, rotate);

labelStyle.Setters.Add(setter);
(xSerie.IndependentAxis as CategoryAxis).AxisLabelStyle = labelStyle;
 
Share this answer
 
Comments
iamgun10a 4-Jan-12 2:39am    
Your solution doesnt work. It do nothing :)
iamgun10a 4-Jan-12 5:03am    
And dont copy-paste not working solution from other sites :)
http://stackoverflow.com/questions/6473360/create-style-to-rotate-axis-label-in-code-behind
cheezman 1-Mar-13 12:51pm    
I have been trying to do something like the above solutions in WPF, given its similarity to Silverlight, but none of these have worked. I am going to try fixing my angles with Expression.

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