我遇到DataPoint问题。图表没有显示任何内容,我希望找出原因。
<Window
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:local="clr-namespace:WpfApplication12" x:Class="WpfApplication12.MainWindow"
Title="MainWindow" Height="300" Width="300">
<ItemsControl ItemsSource="{Binding TestSeries}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Rows="2" Columns="2"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid ShowGridLines="True">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition Height="40"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<oxy:Plot Grid.Row="0" Grid.Column="1">
<!--<oxy:LineSeries ItemsSource="{Binding TestSeries.Value}"/>-->
<oxy:LineSeries ItemsSource="{Binding Value}" />
</oxy:Plot>
<StackPanel Orientation="Horizontal" Grid.Column="0" Grid.Row="1" Grid.ColumnSpan="2">
<Button Width="100" Content="TestButtonAdd"/>
<Button Width="100" Content="TestButtonMinus"/>
<Button Width="100" Content="TestButton"/>
</StackPanel>
<Label Content="Test1" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="53"/>
<Label Content="Test2" HorizontalAlignment="Left" Margin="10,41,0,0" VerticalAlignment="Top" Width="53"/>
<Label Content="Test3" HorizontalAlignment="Left" Margin="10,72,0,0" VerticalAlignment="Top" Width="53"/>
<Label Content="Test4" HorizontalAlignment="Left" Margin="10,103,0,0" VerticalAlignment="Top" Width="74"/>
<Label Content="Test5" HorizontalAlignment="Left" Margin="10,134,0,0" VerticalAlignment="Top" Width="74"/>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
项目没问题,但看不到系列。
using OxyPlot;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace WpfApplication12
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
///
public partial class MainWindow : Window
{
private Dictionary<string, OxyPlot.Series.LineSeries> testSeries;
public Dictionary<string, OxyPlot.Series.LineSeries> TestSeries
{
get { return testSeries; }
set { testSeries = value; }
}
public MainWindow()
{
OxyPlot.Series.LineSeries Test = new OxyPlot.Series.LineSeries();
Test.Points.Add(new DataPoint(1,10));
Test.Points.Add(new DataPoint(2, 10));
OxyPlot.Series.LineSeries Test1 = new OxyPlot.Series.LineSeries();
Test1.Points.Add(new DataPoint(2, 10));
Test1.Points.Add(new DataPoint(1, 10));
TestSeries = new Dictionary<string,OxyPlot.Series.LineSeries>();
TestSeries.Add("1",Test);
TestSeries.Add("2",Test1);
this.DataContext = this;
InitializeComponent();
}
}
}
输出未显示任何绑定错误。
答案 0 :(得分:0)
我换了。而且它正在发挥作用。
using OxyPlot;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.ComponentModel;
namespace WpfApplication12
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
///
public partial class MainWindow : Window,INotifyPropertyChanged
{
private Dictionary<string, IList<DataPoint>> testSeries;
public Dictionary<string, IList<DataPoint>> TestSeries
{
get { return testSeries; }
set { testSeries = value; NotifyPropertyChanged("TestSeries"); }
}
private void NotifyPropertyChanged(String info)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(info));
}
}
public MainWindow()
{
TestSeries = new Dictionary<string, IList<DataPoint>>();
TestSeries.Add("1", new List<DataPoint> { new DataPoint(1, 2), new DataPoint(2, 3) });
TestSeries.Add("2", new List<DataPoint> { new DataPoint(1, 3), new DataPoint(2, 1) });
this.DataContext = this;
InitializeComponent();
}
public event PropertyChangedEventHandler PropertyChanged;
}
}