问题描述:

So I just bought the sync fusion package, and now I want to create a sparkline.

Their documentation states that I can just create a model and pass it as a binding to the sparkline.

This is what I've done. I've created an empty page, with a sparkline object like this:

<Charts:SfLineSparkline x:Name="yay" ItemsSource="{Binding OrderList}" YBindingPath="Number" MarkerVisibility="Visible" HorizontalAlignment="Left" Height="138" VerticalAlignment="Top" Width="456" Background="#FFFF9A9A"/>

In my code behind I've got a model "OrderViewModel" that looks like this:

public class OrderViewModel

{

public OrderViewModel()

{

this.OrderList = new ObservableCollection<Order>();

DateTime date = DateTime.Today;

OrderList.Add(new Order { Number = 2, TimeStamp = date.AddHours(1) });

OrderList.Add(new Order { Number = 3, TimeStamp = date.AddHours(2.3) });

OrderList.Add(new Order { Number = 1, TimeStamp = date.AddHours(4) });

}

public ObservableCollection<Order> OrderList { get; set; }

}

The "Order" class looks like this:

public class Order

{

public DateTime TimeStamp { get; set; }

public int Number { get; set; }

}

So far this is not working.

According to their docs, it says that I have to do something like adding a data context to the grid above, using a local namespace tag, which I don't have.

It's supposed to look like this:

<Grid.DataContext>

<local:OrderViewModel/>

</Grid.DataContext>

I realize that this is probably a real noob question, but I have been trying to get this working for some time now, and it just wont.

This is the docs I'm reffering to :)

http://help.syncfusion.com/UG/Windows%20Phone%208/Documents/creatingsparkline.htm

网友答案:

Replace MyProject with yours.

  xmlns:local="using:MyProject"

Or if the OrderViewModel in another namespace

  xmlns:local="using:MyProject.ViewModels"

You should add it with

  xmlns:Syncfusion="clr-namespace:Syncfusion.UI.Xaml.Charts"

Another way:

Use Properties window if it's closed open it with F4, click the grid tag then go to the DataContext property and press new or the yellow square to select your OrderViewModel.

相关阅读:
Top