私は2,3日前からSilverlightで遊んでいましたが、進歩はしていますが、ロードブロックに当たっています。ifdステートメントを使用してSilverlightの線グラフにデータをロードするときに問題が発生する
私はC#の経験が全くありません(私はPHPプログラマーです)。
私は問題なくデータを表示する折れ線グラフを持っていますが、どの情報が渡されているかによって異なるデータを表示します。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
namespace MyProject
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(UC_Loaded);
}
void UC_Loaded(object sender, RoutedEventArgs e)
{
//int student_id = (int)App.Current.Resources["student_id"];
int student_id = (int)10;
//int test_id = (int)App.Current.Resources["test_id"];
this.DataContext = this;
List<Student> cust = new List<Student>();
if (student_id==10)
{
cust.Add(new Student() { Date = "14th Oct", Result = 30 });
cust.Add(new Student() { Date = "20th Oct", Result = 60 });
cust.Add(new Student() { Date = "30th Oct", Result = 20 });
cust.Add(new Student() { Date = "12th Nov", Result = 10 });
cust.Add(new Student() { Date = "20th Nov", Result = 70 });
}
else
{
cust.Add(new Student() { Date = "14th Oct", Result = 10 });
cust.Add(new Student() { Date = "20th Oct", Result = 10 });
cust.Add(new Student() { Date = "30th Oct", Result = 10 });
cust.Add(new Student() { Date = "12th Nov", Result = 10 });
cust.Add(new Student() { Date = "20th Nov", Result = 10 });
}
this.DataContext = cust;
}
}
public class Student
{
public string Date { get; set; }
public int Result { get; set; }
}
}
私のXAMLはここにある:
次のようにマイxaml.csを働くことで/他の場合は、すべてのセットアップですが、私は試してみて、基本を取得するために戻って一歩を踏み出しています
<Grid x:Name="LayoutRoot" Background="White">
<StackPanel>
<toolkit:Chart Height="500" Width="600" Title="Test title">
<toolkit:Chart.Series>
<toolkit:LineSeries Title="Student Scores"
ItemsSource="{Binding}"
IndependentValueBinding="{Binding Date}"
DependentValueBinding="{Binding Result}">
<toolkit:LineSeries.DataPointStyle>
<Style TargetType="toolkit:LineDataPoint">
<Setter Property="Background" Value="Lime"/>
</Style>
</toolkit:LineSeries.DataPointStyle>
</toolkit:LineSeries>
</toolkit:Chart.Series>
<toolkit:Chart.Axes>
<toolkit:LinearAxis Orientation="Y" Minimum="0" Maximum="100" Interval="5" ShowGridLines="True" FontStyle="Italic"></toolkit:LinearAxis>
</toolkit:Chart.Axes>
</toolkit:Chart>
</StackPanel>
</Grid>
if/elseとcustの1つのセットを使用せずに実行すると、期待通りに動作しますが、if/elseを指定すると、ポイントがない空のグラフが表示されます。
ありがとうございます。
優れたモーセに、私はあなたの仮想飲み物を借りて! –
下記の注釈を参照してください –
リチャードは、私には恥についてINotifyLayoutChangeをどのように追加したか分かりません。 – Landern