Hello,
I’m currently rewriting a program in .net7 WPF using MVVM as much as possible.
In my MainViewModel:
I read data from a CSV file and transforming it into an ObservableCollection of LineRenderableSeriesViewModel (stored in the « RenderableSeriesViewModels » variable) . Additionally, the Y axes are transformed into ObservableCollection of IAxisViewModel (within the « Yaxes » variable).
Each series corresponds to a LineRenderableSeriesViewModel and each Y axis is represented as a NumericAxisViewModel. The X-axis is a DateTime common to all series and is declared only in XAML.
Within my view’s XAML:
I declare RenderableSeries=”{s:SeriesBinding RenderableSeriesViewModels}” and YAxes=”{s:AxesBinding YAxes}. I’ve defined a legend template to add several elements:
– DataContext=”{Binding RenderableSeries}”
– A checkbox to toggle serie visibility (IsVisible binding).
– A checkbox to toggle Y-axis visibility for the serie (YAxis.Visibility binding).
– A color picker to change the color of a serie, bound to “Stroke”, “YAxis.TickTextBrush”, and “YAxis.BorderBrush”
– A slider for adjusting serie thickness (StrokeThickness binding).
Results:
Each element acts on the graph as expected: RenderableSeries updates and the graph refreshes correctly.
In the MainViewModel, RenderableSeriesViewModels and YAxes are not updated for all elements:
– “IsVisible” and “StrokeThickness” for the concerned series are instantly modified in RenderableSeriesViewModels but “Stroke” is not.
– “YAxes” is not updated.
The code for the LegendTemplate and a screenshot of the resulting legend are in the attachements.
Could you please help me to understand what I do wrong?
- Nicolas MARTINEZ asked 12 months ago
- last edited 12 months ago
-
Hi Nicolas, it would be really helpful if you could provide a solution to reproduce any issues you report, otherwise our team has to take your description and try to reproduce it first, before finding a solution. Please attach solutions to the forum post using attachment feature. Max attachment size is 10MB so ensure that bin, obj, packages folders are removed. Best regards, Andrew
-
I will prepare a simplified solution and post it as soon as possible
- You must login to post comments
Hi Nicolas,
I’m glad to inform you that we’ve made additional improvements to the MVVM API, and in particular for the Binding mechanism.
The changes are available in the latest SciChart nightly build v8.0.0.27776.
Please try it out and let us know your feedback.
For more information on how to get our nightly builds you can take a look at the “Integrating SciChart’s NuGet Feed with Visual Studio” section of the following article :
https://support.scichart.com/index.php?/Knowledgebase/Article/View/17232/37/getting-nightly-builds-with-nuget
More details regarding the changes made since the previous release can be found in our Changelog here:
https://www.scichart.com/changelog/scichart-wpf/
With best regards,
Lex
SciChart Technical Support Engineer
- Lex answered 11 months ago
- last edited 11 months ago
- You must login to post comments
Attached a simplified program to show the issue.
The bottom part shows values from the viewmodel (RenderableSeriesViewModel and YAxes), you can see the thickness and serie visibility are changing but not the other properties.
The reason I want to get values from the viewmodel is to save in a json file the user parameters for the chart from the viewmodel and next time he opens the CSV file, the json will be deserialized and RenderableSeriesViewModel and YAxes will be updated accordingly.
Thank you in advance
Regards
- Nicolas MARTINEZ answered 12 months ago
-
Hi Nicolas, thanks for the example! We’ve checked it on our side and been able to reproduce the issue immediately. Preliminary investigation shows that it happens because Bindings to ViewModel properties in question are removed and replaced with local values. This can happen when a Binding is OneWay and a property is set directly. In your case, this seems to happen when values are updated by the Legend. We’ve logged the issue in our issue tracked and going to look into it further. We will update you when have any news. Best regards, Joeri
-
Thank you.
-
In the meantime I’ve implemented a provisional solution by updating the properties of the ViewModel from the code-behind, though it’s not the most elegant approach. Just so you’re aware, I had to modify the type of YAxes from ObservableCollection(IAxisViewModel) to ObservableCollection(NumericAxisViewModel) since the BorderBrush property isn’t accessible from IAxisViewModel.
- You must login to post comments
Hi Nicolas,
I’ve taken a quick look at the reported problem, and can confirm Joery’s suspicions, that there is a problem with our legend style bindings, where we have some of them as ‘OneWay’ and some of them are of custom xaml extensions(SciChart themebinding). I’m working on fixing that problem, but meanwhile I want to suggest you the following workaround:
** Inside your ‘SciChartSurface.Resources’ section you were binding everything directly to an Axis, like this:
IsChecked="{Binding Path=YAxis.Visibility, Mode=TwoWay, Converter={StaticResource VisibilityToBooleanConverter}}"
and then this value is re-seted via ViewModel. So I’d suggest you bind everything you need to an YAxis.DataContext like this:
IsChecked="{Binding Path=YAxis.DataContext.Visibility, Mode=TwoWay, Converter={StaticResource VisibilityToBooleanConverter}}"
- Please try this and give us your feedback on this.
- Also please find attached modified example you’ve sent us.
- Nathaniel D answered 12 months ago
- You must login to post comments
Thank you very much.
I will test it further, but it seems to work as expected.
For your information, I also made a modification:
From:
<Binding Mode="TwoWay" Path="Stroke" />
To:
<Binding Mode="TwoWay" Path="DataContext.Stroke" />
in order to get the color to change.
Thank you again for your support,
Best Regards
NM
- Nicolas MARTINEZ answered 12 months ago
- You must login to post comments
Please login first to submit.