我对C#& amp; WPF,我无法将数据绑定到lineSeries。
我已经完成了一些示例,但我不明白如何绑定数据
我需要绑定Dictionary中的数据。 Plotgraph.cs:
internal class Plotgraph : ICommand
{
private ViewModel viewModel;
public Plotgraph(ViewModel viewModel)
{
this.viewModel = viewModel;
}
public event EventHandler CanExecuteChanged;
public bool CanExecute(object parameter) => true;
public void Execute(object parameter)
{
viewModel.Model.GetParameterValues(viewModel.SelectedParameter.Name);
}
}
我在Window.xaml中有图表
<ChartingControls:Chart Title="Parameter Values v/s TimeStamp" x:Name="GraphPlot" Grid.Row="1" Grid.Column="0">
<ChartingControls:LineSeries x:Name="ParameterTimeStamp"
Title="{Binding Path=SelectedParameter.Description}" DependentValuePath="Value"
IndependentValuePath="Key" ItemsSource="{Binding PlotParameter}">
</ChartingControls:LineSeries>
<ChartingControls:Chart.Axes>
<ChartingControls:LinearAxis
Orientation="X"
Title="TimeStamp"
Interval="50" Minimum="0" Maximum="{Binding Path=Mission.DataLength}"/>
<ChartingControls:LinearAxis
Orientation="Y"
Title="Values"
Interval="30" Minimum="{Binding Path=SelectedParameter.MinimumValue}"
Maximum="{Binding Path=SelectedParameter.MaximumValue}"/>
</ChartingControls:Chart.Axes>
</ChartingControls:Chart>
window.cs看起来像
public partial class GraphPlotUIWindow : Window
{
public GraphPlotUIWindow(IViewModel viewModel)
{
InitializeComponent();
DataContext = viewModel;
}
}
我在Iviewmodel和viewmodel中添加了PlotParameter,如下所示:
IViewModel.cs:
Dictionary<int, double> PlotParameter { get; set; }
ViewModel.cs:
public Dictionary<int, double> plotparameter;
public Dictionary<int, double> PlotParameter
{
get
{
return plotparameter;
}
set
{
OnPropertyChanged(nameof(PlotParameter));
}
}
但数据集在Model.cs中可用:
public Dictionary<int, double> ParameterDataSet;
public Dictionary<int, double> GetParameterValues(string name)
{
var parameterValues = tcpServiceClient.GetParameterValues(name);
ParameterDataSet = new Dictionary<int, double>();
foreach (var item1 in parameterValues)
{
var key = item1.TimeStamp;
var value = item1.Value;
ParameterDataSet.Add(key, value);
}
return ParameterDataSet;
}
我已经阅读了这个例子。我还在黑暗中,我没有得到我在做错的地方......
请帮助我,
提前致谢...