2012-02-22 40 views
0

我已经编程创建了一个WPF图表,并且想要更改标题的字体和颜色,我可以设置图表的宽度和高度,但不是标题,我在网上找到的所有示例都向您展示了如何通过XAML进行操作。但我需要能够在代码中完成所有工作。如何在代码中更改WPF图表的标题字体?

 this._chart.Width = this.ChartWidth; 
     this._chart.Height = this.ChartHeight; 
     this._chart.Background = Brushes.Transparent; 
     .... 
     this._chart.Title ???? 

谢谢。

回答

0

最简单的方法是使用TextBlock控件,而不是纯文本:

this._chart.Title = new TextBlock 
{ 
    Text = "My title", 
    FontFamily = new FontFamily("Arial"), 
    Foreground = Brushes.Red 
}; 

同样的方法可以用图例标题中使用。顺便说一下,您可以使用任何WPF控件,而不仅仅是文本块。

this._chart.LegendTitle = new TextBlock { Text = "legend", Foreground = Brushes.Red }; 

如果要更改样式属性像PloatAreaStyle,愿意这样做:

var plotAreaStyle = new Style(typeof(Grid)); 
plotAreaStyle.Setters.Add(new Setter(Grid.BackgroundProperty, Brushes.LightBlue)); 

this._chart.PlotAreaStyle = plotAreaStyle; 
+0

@Vortex,TNX很多,工作就像一个魅力:-) – MaYaN 2012-02-23 09:46:21

+0

@Vortex,只是跟进这个,我需要找到为图表设置不同属性的值的机制,例如图例或图表区域。在asp.net图表中,事情很容易设置,但是在WPF中,我无法弄清楚如何在不使用XAML的情况下设置值。如果您能证明设置图表属性而不使用XAML(即图例或图表区域)的机制,我将不胜感激。 – MaYaN 2012-02-23 10:03:43

+0

@ ALIR.Bousari最好指定要设置的属性或演示要重写的xaml代码。我假设你想看到的属性是LegendTitle和PlotAreaStyle。 – vorrtex 2012-02-23 10:54:05

相关问题