ฉันกำลังรับข้อมูลแบบอะซิงโครนัสและพยายามเติมข้อมูลพล็อตผ่าน LineSeries ยกเว้นว่าพล็อตไม่รีเฟรชเมื่อมีการอัปเดตคอลเลกชันที่ถูกผูกไว้ (ObservableCollection) หมายเหตุ: ฉันมีพฤติกรรม XAML ที่จะเรียก InvalidatePlot(true) เมื่อการเปลี่ยนแปลงคอลเลกชันที่ถูกผูกไว้
มีใครอธิบายได้บ้างว่าทำไมโครงเรื่องจึงไม่อัปเดตตามที่คาดไว้
WPF .Net 4.0 OxyPlot 2014.1.293.1
ฉันมีเทมเพลตข้อมูล XAML ต่อไปนี้ ตามที่คุณเห็น LineSeries ItemsSource ถูกผูกไว้กับคุณสมบัติ (PlotData) ใน ViewModel:
<DataTemplate DataType="{x:Type md:DataViewModel}">
<Grid>
<oxy:Plot x:Name="MarketDatePlot"
Margin="10">
<oxy:Plot.Axes>
<oxy:DateTimeAxis Position="Bottom"
StringFormat="dd/MM/yy"
MajorGridlineStyle="Solid"
MinorGridlineStyle="Dot"
IntervalType="Days"
IntervalLength="80" />
<oxy:LinearAxis Position="Left"
MajorGridlineStyle="Solid"
MinorGridlineStyle="Dot"
IntervalLength="100" />
</oxy:Plot.Axes>
<oxy:LineSeries ItemsSource="{Binding Path=PlotData, Mode=OneWay}" />
<i:Interaction.Behaviors>
<behaviors:OxyPlotBehavior ItemsSource="{Binding Path=PlotData, Mode=OneWay}" />
</i:Interaction.Behaviors>
</oxy:Plot>
</Grid>
</DataTemplate>
ดังที่ฉันกล่าวว่าคำขอ ViewModel และเติมคอลเลกชันที่ถูกผูกไว้แบบอะซิงโครนัส (จำนวนจริงของคอลเลกชันที่ถูกผูกไว้เกิดขึ้นบนเธรด UI):
public sealed class DataViewModel : BaseViewModel, IDataViewModel
{
private readonly CompositeDisposable _disposable;
private readonly CancellationTokenSource _cancellationTokenSource;
private readonly RangeObservableCollection<DataPoint> _plotData;
public DataViewModel(DateTime fromDate, DateTime toDate, IMarketDataService marketDataService, ISchedulerService schedulerService)
{
_plotData = new RangeObservableCollection<DataPoint>();
_disposable = new CompositeDisposable();
if (fromDate == toDate)
{
// nothing to do...
return;
}
_cancellationTokenSource = new CancellationTokenSource();
_disposable.Add(Disposable.Create(() =>
{
if (!_cancellationTokenSource.IsCancellationRequested)
{
_cancellationTokenSource.Cancel();
}
}));
marketDataService.GetDataAsync(fromDate, toDate)
.ContinueWith(t =>
{
if (t.IsFaulted)
{
throw new Exception("Failed to get market data!", TaskHelper.GetFirstException(t));
}
return t.Result.Select(x => new DataPoint(DateTimeAxis.ToDouble(x.Time), x.Value));
}, schedulerService.Task.Default)
.SafeContinueWith(t => _plotData.AddRange(t.Result), schedulerService.Task.CurrentSynchronizationContext);
}
public void Dispose()
{
_disposable.Dispose();
}
public IEnumerable<DataPoint> PlotData
{
get { return _plotData; }
}
}
และพฤติกรรม XAML มีลักษณะดังนี้:
(ดูเหมือนว่าฉันไม่สามารถวางโค้ดได้อีกต่อไป ดังนั้นจึงเกิดข้อผิดพลาดในการบันทึก)
RangeObservableCollection
คืออะไร? นอกจากนี้ มันจะสร้างความแตกต่างหรือไม่หากพร็อพเพอร์ตี้ของคุณเป็นObservableCollection
แทนที่จะเป็นIEnumerable<>
ฉันรู้ว่าสมาชิกข้อมูลพื้นฐานคือ (สมมติว่าRangeObservableCollection
มาจากObservableCollection
) แต่ฉันไม่แน่ใจว่านั่นดีเพียงพอสำหรับระบบการเชื่อมโยงหรือไม่ - person Tim   schedule 08.05.2014