J'utilise LiveChart Library et j'ai un problème pour afficher les graphiques. En effet, dans ma fenêtre, je veux beaucoup de graphiques avec de nombreux types, donc j'utilise un DataTemplateSelector, un lien vers une classe pour chaque type de graphique. Mais, quand le graphique apparaît, il n'y a pas de données à ce sujet. J'ai essayé d'ajouter DataContext="{Binding}"
dans la déclaration de mon "Column Graph" mais sans succès.CartesianChart (Live-Charts) ne fonctionne pas avec DataTemplate
Voici un extrait de mon code:
ResultView.xaml
<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">
<FrameworkElement.Resources>
<DataTemplate x:Key="graphEmptyTemlpate">
<StackPanel Width="Auto" Height="60" Orientation="Horizontal" MaxWidth="700">
<TextBlock Text="{Binding name}" VerticalAlignment="Center" TextAlignment="Center" FontSize="20" Margin="0,0,0,0" Foreground="#FF006B93"/>
</StackPanel>
</DataTemplate>
<DataTemplate x:Key="columnTemplate">
<StackPanel Background="#FFBFBFBF">
<TextBlock Text="{Binding title}"/>
<TextBlock Text="{Binding subTitle}"/>
<lvc:CartesianChart Width="400" Height="400" Series="{Binding listSeries}">
</lvc:CartesianChart>
</StackPanel>
</DataTemplate>
<local:GraphTemplateSelector
ColumnTemplate="{StaticResource columnTemplate}"
GraphEmptyTemplate="{StaticResource graphEmptyTemlpate}"
x:Key="graphTemplateSelector" />
</FrameworkElement.Resources>
<StackPanel Orientation="Horizontal" >
<ItemsControl ItemsSource="{Binding Results}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Expander Header="{Binding Title}"
IsExpanded="True"
Margin="10 10 10 10"
FontSize="20"
Foreground="White">
<ItemsControl ItemsSource="{Binding Items}"
ItemTemplateSelector="{DynamicResource graphTemplateSelector}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Margin="10 10 10 10" Orientation="Vertical"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</Expander>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</ScrollViewer>
le constructeur de ma classe ViewModel est en ResultViewModel.cs Dans le XAML, les résultats correspondent aux résultats en C#, correspond Articles à RpAgitation.Items en C#
public ResultsViewModel()
{
instance = this;
this.Results = new ObservableCollection<ResultParts>();
this.RpAgitation = new ResultParts("Results of the Agitation part");
ColumnGraph gr = new ColumnGraph();
RpAgitation.Items.Add(gr);
this.Results.Add(_rpAgitation);
}
et finnaly les ColumnGraph.cs
public class ColumnGraph : IGraph
{
public SeriesCollection listSeries { get; set; }
public ColumnGraph()
{
listSeries = new SeriesCollection
{
new LineSeries
{
Title = "Series 1",
Values = new ChartValues<double> { 4,7,8,9,5,4,2}
}
};
}
}
Merci pour votre aide,
Merci pour l'ouverture de la question dans la mise en pension, je fixerai dès que possible –
c'est déjà corrigé depuis la version 0.7.7 –
Merci beaucoup! – bobbinch