簡體   English   中英

如何在代碼中更改WPF圖表的標題字體?

[英]How do you change the Title Font for a WPF Chart in code?

我已經以編程方式創建了WPF圖表,並且想要更改“標題”的字體和顏色,我可以設置圖表的寬度和高度,但不能設置標題,我在網上找到的所有示例都向您展示了如何通過XAML進行操作。 但是我需要能夠用代碼完成所有這些工作。

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

謝謝。

最簡單的方法是使用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;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM