Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
98 lines (66 sloc) 3.42 KB

Windows Phone Silverlight

Note

This section is under construction. Please contribute!

This example shows how to create a Windows Phone Silverlight app.

Create project

Start Visual Studio and select "FILE -> New -> Project...". Select "Windows -> Windows 8 -> Windows Phone -> Blank App (Windows Phone Silverlight)" to create a new projects for Windows Phone Silverlight.

Add references

You need references to the OxyPlot and OxyPlot.WP8 assemblies. The easiest way to do this is to right click on the "References" item in the Solution Explorer and select "Manage NuGet Packages..." (this requires that the "NuGet Package Manager" extension is installed).

In the "Manage NuGet packages" dialog, search for "oxyplot.windows" in the top-right search textbox. Select the "OxyPlot.Windows" package and click install.

You can also use the Package Manager Console to install the package:

PM> Install-Package OxyPlot.Windows

Create a view model

Add a class that creates a PlotModel and a FunctionSeries.

namespace WinPhoneApp1
{
    using System;

    using OxyPlot;
    using OxyPlot.Series;

    public class MainViewModel
    {
        public MainViewModel()
        {
            this.MyModel = new PlotModel { Title = "Example 1" };
            this.MyModel.Series.Add(new FunctionSeries(Math.Cos, 0, 10, 0.1, "cos(x)"));
        }

        public PlotModel MyModel { get; private set; }
    }
}

Create the view

Define the namespace in the PhoneApplicationPage element, set the DataContext and add a PlotView control:

<phone:PhoneApplicationPage
    x:Class="WinPhoneApp1.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:oxy="clr-namespace:OxyPlot.WP8;assembly=OxyPlot.WP8"
    xmlns:local="clr-namespace:WinPhoneApp1"
    mc:Ignorable="d"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Landscape" Orientation="Landscape"
    shell:SystemTray.IsVisible="True">
    <phone:PhoneApplicationPage.DataContext>
        <local:MainViewModel/>
    </phone:PhoneApplicationPage.DataContext>

    <Grid x:Name="ContentPanel" Margin="12,0,12,0">
        <oxy:PlotView Model="{Binding MyModel}"/>
    </Grid>

</phone:PhoneApplicationPage>

The application should now look like this (on the Windows Phone emulator):

wp8-example1.png

The source code can be found in the HelloWorld\WinPhoneApp1 folder in the documentation-examples repository.

You can’t perform that action at this time.