We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Problem with DataBinding to Series

Hello,
I have a treeview and when I click on an item I want to refresh a WPF default grid and also a sfchart control. My XAML Looks like this:

    <Window.DataContext>
        <viewModel:VMmainWindow />
    </Window.DataContext>
    <Grid Margin="0,10,2,0">
        <DataGrid x:Name="dataGrid" Margin="0,10,218,329" ItemsSource="{Binding SelectedStock.StockData}" HorizontalAlignment="Right" Width="405" />
        <syncfusion:TreeViewAdv ItemsSource="{Binding Indices}" SelectedTreeItem="{Binding SelectedStock}" Margin="10,10,628,329">
            <syncfusion:TreeViewAdv.ItemTemplate>
                <HierarchicalDataTemplate ItemsSource="{Binding Stocks}">
                    <TextBlock Text="{Binding Symbol}" />
                </HierarchicalDataTemplate>
            </syncfusion:TreeViewAdv.ItemTemplate>
        </syncfusion:TreeViewAdv>
        <DockPanel HorizontalAlignment="Left" Height="314" LastChildFill="False" Margin="10,235,0,0" VerticalAlignment="Top" Width="770">
            <syncfusion:SfChart x:Name="Chart"   Margin="5,0,10,0">
                <syncfusion:SfChart.DataContext>
                    <viewModel:VMmainWindow></viewModel:VMmainWindow>
                </syncfusion:SfChart.DataContext>
                <syncfusion:SfChart.PrimaryAxis>
                    <syncfusion:DateTimeAxis  Header="Date"/>
                </syncfusion:SfChart.PrimaryAxis>
                <syncfusion:SfChart.SecondaryAxis>
                    <syncfusion:NumericalAxis  Header="Value"/>
                </syncfusion:SfChart.SecondaryAxis>
                <syncfusion:LineSeries  x:Name="series1" XBindingPath="Date" YBindingPath="Close" ItemsSource="{Binding SelectedStock.StockData}"/>
            </syncfusion:SfChart>
        </DockPanel>
    </Grid>

My ViewModel:
    public class VMmainWindow
    {
        public List<Model.Index> Indices { get; set; }
        public Model.Stock SelectedStock { get; set; }
        public VMmainWindow()
        {
            this.Indices = new List<Model.Index>();
            this.Indices.Add(new Model.Index());
        }

For the moment I haven't implemented INotifyPropertyChanged in my model classes though the datagrid is already correctly updated when I Change the selection in the treeview, but the sfchart isn't (stays empty).
What can I do that this works?
Thanks in advance!

Melvin


3 Replies

SJ Sumathi Jayaraj Syncfusion Team March 21, 2016 04:33 PM UTC

Hi Melvin,

Thanks for contacting Syncfusion Support.

We are unable to reproduce your reported problem. Please provide us more information probably a sample to reproduce the reported issue.

Regards,
Sumathi J


MS Melvin Smith March 21, 2016 05:52 PM UTC

Hi Sumathi,
I attached a zip Folder with my solution.
You will see that selecting an item in the treeview will refresh the grid, but not the Chart. Could you tell me why this isn't the case ?
Best regards
Melvin

Attachment: HistoricalStockDataGetter_b54ee62d.zip


SJ Sumathi Jayaraj Syncfusion Team March 22, 2016 10:33 AM UTC

Hi Melvin,
 
Thanks for the update.
 
The problem occurs because the Window and SfChart are having their own DataContext. We have resolved the problem in the sample by removing DataContext from SfChart. Please find the modified sample from the below location.
 
Sample: HistoricalStockDataGetter
 
Regards,
Sumathi J

Loader.
Live Chat Icon For mobile
Up arrow icon