2014-05-09 26 views
0

我創造我的Windows Phone app.this圖表是我的代碼XAML如何從代碼中的windows phone顯示圖表背後

<amq:SerialChart x:Name="line" DataSource="{Binding results}" CategoryValueMemberPath="month" 
AxisForeground="White" 
PlotAreaBackground="Black" 
GridStroke="DarkGray" > 
       <amq:SerialChart.Graphs> 
        <amq:LineGraph Title="Sales" ValueMemberPath="actual" Brush="red" StrokeThickness="5" /> 
       </amq:SerialChart.Graphs> 

      </amq:SerialChart> 

我怎麼可以這樣寫XAML與C#(僅次於代碼)

回答

1

我怎麼可以這樣寫XAML與C#(代碼僅落後)

一般來說,這通常不是一個好主意。但是,如果你一定要,你會使用的東西沿着這些路線:

var chart = new SerialChart 
{ 
    CategoryValueMemberPath = "month", 
    AxisForeground = new SolidColorBrush(Colors.White), 
    PlotAreaBackground = new SolidColorBrush(Colors.Black), 
    GridStroke = new SolidColorBrush(Colors.DarkGray) 
}; 
chart.SetBinding(SerialChart.DataSourceProperty, new Binding("results")); 

var lineGraph = new LineGraph 
{ 
    Title = "Sales", 
    ValueMemberPath = "actual", 
    Brush = new SolidColorBrush(Colors.Red), 
    StrokeThickness = "5" 
}; 
chart.Graphs.Add(lineGraph); 

那麼你就只需要圖表添加到使用例如stackPanel.Children.Add(chart)頁/容器。

+0

AxisForeground = 「白」, PlotAreaBackground = 「黑」, GridStroke = 「深灰」 錯誤消息 「無法隱式轉換類型 '字符串' 到 'System.Windows.Media.Brush'」 – user3433797

+0

@ user3433797更新超過 – McGarnagle

0
var chart = new SerialChart 
{ 
    CategoryValueMemberPath = "month", 
    AxisForeground = new SolidColorBrush(Colors.White), 
    PlotAreaBackground = new SolidColorBrush(Colors.Black), 
    GridStroke = new SolidColorBrush(Colors.DarkGray) 
}; 
chart.SetValue(SerialChart.DataSourceProperty, new Binding("results")); 

var lineGraph = new LineGraph 
{ 
    Title = "Sales", 
    ValueMemberPath = "actual", 
    Brush = new SolidColorBrush(Colors.Red), 
    StrokeThickness = 5 
}; 
chart.Graphs.Add(lineGraph); 
+1

的任何解釋 – tod

相關問題