我是 Silverlight 的新手,我只是想了解如何做一些事情。我想做的是有一个图表,它有两条可能相互重叠的线。我的代码发生的情况是显示一行,然后显示下一行,一个接一个,而不是重叠。
这是我的xml
<navigation:Page x:Class="SilverlightNav1.Home"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
xmlns:charting="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"
mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="547"
Title="Home"
Style="{StaticResource PageStyle}" xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk" xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit">
<Grid x:Name="LayoutRoot" Height="544">
<sdk:Label Height="28" HorizontalAlignment="Left" Margin="12,12,0,0" Name="label1" VerticalAlignment="Top" Width="120" Content="First Name" />
<TextBox Height="23" Margin="91,8,0,0" Name="txtFirstName" VerticalAlignment="Top" HorizontalAlignment="Left" Width="120" >
<TextBox.RenderTransform>
<SkewTransform AngleX="2" AngleY="12" />
</TextBox.RenderTransform>
<TextBox.Effect>
<DropShadowEffect />
</TextBox.Effect>
</TextBox>
<Button Content="Greet Me" Height="23" HorizontalAlignment="Left" Margin="91,72,0,0" Name="GreetMe" VerticalAlignment="Top" Width="75" Click="GreetMe_Click" />
<TextBlock Margin="91,116,25,0" Name="Greeting" Text="" Height="105" VerticalAlignment="Top" FontSize="20" />
<toolkit:Chart HorizontalAlignment="Left" Margin="21,246,0,0" Name="chart1" Title="Testing graph" VerticalAlignment="Top" Height="249" Width="400">
<toolkit:Chart.Series>
<toolkit:LineSeries Title="Guys" ItemsSource="{Binding p}" IndependentValueBinding="{Binding FirstName}" DependentValueBinding="{Binding Greeting}" Name="testGraph">
</toolkit:LineSeries>
<toolkit:LineSeries Title="Girls" ItemsSource="{Binding girls}" IndependentValueBinding="{Binding FirstName}" DependentValueBinding="{Binding Greeting}" Name="lsGirls">
</toolkit:LineSeries>
</toolkit:Chart.Series>
</toolkit:Chart>
</Grid>
这是我的代码隐藏。
List<Model.Person> p = new List<Model.Person>();
p.Add(new Model.Person() { FirstName = "Bob", Greeting = 1 });
p.Add(new Model.Person() { FirstName = "Phil", Greeting = 3 });
p.Add(new Model.Person() { FirstName = "Dennis", Greeting = 4});
p.Add(new Model.Person() { FirstName = "Chewie", Greeting = 2 });
//this.DataContext = p;
List<Model.Person> girls = new List<Model.Person>();
girls.Add(new Model.Person() { FirstName = "Jamie", Greeting = 4 });
girls.Add(new Model.Person() { FirstName = "Abby", Greeting = 7 });
girls.Add(new Model.Person() { FirstName = "M", Greeting = 5 });
girls.Add(new Model.Person() { FirstName = "K", Greeting = 6 });
((LineSeries)chart1.Series[0]).ItemsSource = p;
((LineSeries)chart1.Series[1]).ItemsSource = girls;
最后这是我在 person.cs 中定义的类
namespace SilverlightNav1.Model
{
public class Person
{
private string _firstName;
public string FirstName
{
get { return _firstName; }
set
{
_firstName = value;
}
}
private int _greeting;
public int Greeting
{
get { return _greeting; }
set { _greeting = value; }
}
}
}