12-12-2017 04:50 AM
Hi,
I am using MVVM pattern and want to create a user control which contains a graph control.
I want to bind my plots and axes as described in Wpf Graph Binding and defining Axes and Plots only in ViewModel.
Everything seems ok when there is a one user control on page.
When I want to put 2 user controls on a page GraphExtension class throws "Child is already registered with a IRenderableGraph'1 parent" exception on a synchronizer.SourceCollection = CollectionViewSource.GetDefaultView( e.NewValue ); line.
// Retrieve existing synchronizer, or create a new one for the target graph.
var synchronizer = (CollectionViewSynchronizer)graph.GetValue( PlotsSynchronizerProperty );
if( synchronizer == null ) {
synchronizer = new CollectionViewSynchronizer { TargetCollection = graph.Plots };
graph.SetValue( PlotsSynchronizerProperty, synchronizer );
}
// Synchronize graph's plots with new source.
synchronizer.SourceCollection = CollectionViewSource.GetDefaultView( e.NewValue );
}
How can I correct error ?
Thanks in advance
Hakan
Solved! Go to Solution.
12-12-2017 10:19 AM
The exception is raised because an individual plot or axis object can only appear in one graph (although configuration values, like renderers and ranges can be shared).
In other words, each user control needs to provide a unique set of plots for its own graph. This can be done on the model side (by exposing unique plots everywhere you use the PlotsSource
attached property), or it can be done in the attached property itself (by setting a custom synchronizer.ItemConverter = item => /* create Plot from source value */
item converter callback).
12-12-2017 11:45 PM
I changed my code as
synchronizer.ItemConverter = item => new Plot(){Rendere = ((Plot)item).Renderer} and evertythings seems to OK.
Thank you for answer.
Best Regards,
Hakan.