我需要创建一个旋转x轴标签的样式。 我找到了以下示例:Easily rotate the axis labels of a Silverlight/WPF Toolkit chart和Rotating Text以及How to change AxisLabelStyle in code behind?
我需要在后面的代码中执行此操作。所以我试过这个:
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;
我想我在RenderTransformProperty上犯了一些错误。
我该怎么办?谢谢!
编辑: 我刚刚将我的代码更新为:
var labelStyle = new Style(typeof(AxisLabel));
var setter = new Setter(AxisLabel.RenderTransformProperty, new RotateTransform(){Angle = -60, CenterX = 40, CenterY = 30});
labelStyle.Setters.Add(setter);
现在它运作正常!
答案 0 :(得分:2)
如果您是从代码中执行此操作,则应专注于操作转换集合。
var group = new TransformGroup();
group.Children.Add(new RotateTransform() { Angle = 270 });
control.RenderTransform = group;
或者,将您的转换添加到现有的RenderTransform
:
TransformGroup renderTransform = control.RenderTransform as TransformGroup;
if (renderTransform != null)
{
RotateTransform rotate = renderTransform.Children
.FirstOrDefault(o => o is RotateTransform as RotateTransform
if(rotate == null)
{
rotate = new RotateTransform();
renderTransform.Children.Add(rotate);
}
rotate.Angle = 270;
}
哦,你应该考虑一下你的RenderTransformOrigin
:
control.RenderTransformOrigin = new Point(0.5, 0.5);