我能够将过滤器应用于ObservableCollection,并且它适用于我在XAML代码中的列表框和数据网格,但是我的图表没有更新。所有都具有相同的DataContext。
XAML的代码:
<ListBox Name="lst" ItemsSource="{Binding Measurements}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding sDate}"></TextBlock>
<TextBlock Text="{Binding Place}"></TextBlock>
<TextBlock Text="{Binding Consumtion}"></TextBlock>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<tk:Chart Margin="0,20,0,0" Name="chart" Title="{Binding ElementName=place, Path=SelectedItem.Content}" Height="279">
<tk:ColumnSeries IndependentValuePath="sDate" DependentValuePath="Consumtion" Title="Consumtion" ItemsSource="{Binding}"></tk:ColumnSeries>
<tk:Chart.Axes>
<tk:CategoryAxis Orientation="X" Title="Personer"></tk:CategoryAxis>
<tk:CategoryAxis Orientation="Y" Title="Förbrukning (kWh)"></tk:CategoryAxis>
</tk:Chart.Axes>
</tk:Chart>
<DataGrid Margin="0,20,0,0" Name="grid"></DataGrid>
C#代码:
DataContext = vm;
chart.DataContext = vm.Measurements;
grid.ItemsSource = vm.Measurements;
我通过按下按钮来应用过滤器,列表框和gridview更新但不更新图表,是否有办法更新图表?