none
Oxyplot - Titel bzw. Daten aktualisieren RRS feed

  • Frage

  • Hallo zusammen,

    ich möchte mich etwas in Oxyplot und Data Bindings einarbeiten, da ich gerne Daten eines Sensors visualisieren möchte.
    Dazu habe ich mir ein Oxyplot Beispiel angeschaut, welches so aussieht:

    MainViewModel.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using OxyPlot;
    
    namespace Plot
    {
        public class MainViewModel
        {
            public string Title { get; private set; }
            public IList<DataPoint> Points { get; private set; }
       
            public MainViewModel()
            {
                this.Title = "Example 2";
                this.Points = new List<DataPoint>
                                  {
                                      new DataPoint(0, 4),
                                      new DataPoint(10, 13),
                                      new DataPoint(20, 15),
                                      new DataPoint(30, 16),
                                      new DataPoint(40, 12),
                                      new DataPoint(50, 12)
                                  };
            }
    
            public void SetTitle(string Title)
            {
                this.Title = Title;
            }
        }
    }
    

    XAML:

    <Window x:Name="Main" x:Class="Plot.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:oxy="http://oxyplot.org/wpf"
            xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
            xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
            xmlns:local="clr-namespace:Plot"
            mc:Ignorable="d"
            Title="MainWindow" Height="350" Width="525" Loaded="Main_Loaded">
        <Window.DataContext>
            <local:MainViewModel/>
        </Window.DataContext>
        <Grid>
            <oxy:PlotView x:Name="Plot" Title="{Binding Title}">
                <oxy:PlotView.Series>
                    <oxy:LineSeries ItemsSource="{Binding Points}"/>
                </oxy:PlotView.Series>
            </oxy:PlotView>
        </Grid>
    </Window>
    

    Jetzt würde ich gerne den Titel bzw. die Daten in dem Plot ändern wollen und den Plot danach aktualisieren. Oxyplot macht das wohl von sich aus nicht alleine. 
    Wie bekomme ich das nun recht einfach bewerkstelligt?

    Danke für die Hilfe!

    Donnerstag, 20. August 2015 15:12

Antworten