2016-07-12 26 views
2

私はLiveChartライブラリを使用していますが、グラフを表示するのに問題があります。実際、私のウィンドウでは、多くの種類のチャートが必要です。そのため、グラフの種類ごとにクラスにリンクするDataTemplateSelectorを使用します。しかし、グラフが表示されても、データは表示されません。私はDataContext="{Binding}"を "Column Graph"の宣言に追加しようとしましたが、成功しませんでした。ここでCartesianChart(Live-Charts)はDataTemplateで動作しません

は、私のコードの抜粋です:

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> 

私のViewModelクラスのコンストラクタはXAMLでResultViewModel.cs であり、結果は、アイテムの対応、C#での結果に対応しますColumnGraph.cs 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); 

} 

でRpAgitation.Itemsへとfinnaly

あなたの助けのためのの
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} 
      } 
     }; 
    } 
} 

おかげで、ないWPF UiFramework要素で

+0

おかげで、私が修正されますasap –

+0

0.7.7版 –

+0

これは既にありがとう! – bobbinch

答えて

0

現在のSeriesCollectionクラスは、私は本当にdidn'tにしたいが、私たちはtがこの問題を回避するためにそれを行う必要があると思います。

これはWPFのバグかどうかわかりませんが、私たちは間違っています。

任意の方法、今の代替は、この構文を試してみることですために、私は、さらに調査します:レポで問題を開くための

DataSource = new List<ChartValues<double>> 
     { 
      new ChartValues<double> {r.Next(0, 10), r.Next(0, 10), r.Next(0, 10)}, 
      new ChartValues<double> {r.Next(0, 10), r.Next(0, 10), r.Next(0, 10)}, 
      new ChartValues<double> {r.Next(0, 10), r.Next(0, 10), r.Next(0, 10)} 
     }; 

     DataContext = this; 

とXAML

<ItemsControl ItemsSource="{Binding DataSource}"> 
      <ItemsControl.ItemTemplate> 
       <DataTemplate> 
        <lvc:CartesianChart Height="400"> 
         <lvc:CartesianChart.Series> 
          <lvc:LineSeries Values="{Binding}"></lvc:LineSeries> 
         </lvc:CartesianChart.Series> 
        </lvc:CartesianChart> 
       </DataTemplate> 
      </ItemsControl.ItemTemplate> 
     </ItemsControl>