2011-06-29 23 views
2

我無法獲得軸作爲貨幣格式,任何想法?如何在代碼AxisLabel中爲DependentRangeAxis設置格式?

我在做什麼錯?我需要能夠隨時更改格式,並且爲了進行此測試,我希望將其設置爲值的範圍內的Y軸貨幣。

有人嗎?

謝謝...

var columnSeries = new ColumnSeries 
           { Title = reportProcedureNode.Value, 
            IndependentValuePath = "PrimaryKey", 
            DependentValuePath = "Value", 
            IndependentAxis = new CategoryAxis { Orientation = AxisOrientation.X, ShowGridLines = false, Location = AxisLocation.Bottom}, 
            DependentRangeAxis = new LinearAxis(){Orientation = AxisOrientation.Y, ShowGridLines = false} 
           }; 

     var labelStyle = new Style(typeof(AxisLabel)); 
     labelStyle.Setters.Add(new Setter(AxisLabel.StringFormatProperty, "{}{0:C0}")); 

     var axis = (LinearAxis)columnSeries.DependentRangeAxis; 
     axis.AxisLabelStyle = labelStyle; 

回答

3

在製圖工具包我WPF4版本,你的代碼崩潰。我需要改變:

labelStyle.Setters.Add(new Setter(AxisLabel.StringFormatProperty, "{}{0:C0}")); 

到:

labelStyle.Setters.Add(new Setter(AxisLabel.StringFormatProperty, "{0:C0}")); 

也就是說,除去{}。所述{}來自標記擴展語法:

和由XAML被解析爲內部"{...}"標記擴展時,才需要。

由於您直接設置屬性,因此不會涉及任何標記擴展,並且包括它會阻止顯示真正的貨幣格式。

+0

非常感謝。那就是訣竅。 – nitefrog

相關問題