I create a stack chart and it has 2 seriesDefinition. It work fine.
<chartingToolkit:Chart>
<chartingToolkit:StackedColumnSeries>
<chartingToolkit:SeriesDefinition
DataContext="{Binding Path=CostDetail[0]}"
ItemsSource="{Binding fees}"
DependentValuePath="Fee"
IndependentValuePath="PrjName"
Title="{Binding title}"/>
<chartingToolkit:SeriesDefinition
DataContext="{Binding Path=CostDetail[1]}"
ItemsSource="{Binding fees}"
DependentValuePath="Fee"
IndependentValuePath="PrjName"
Title="{Binding title}"/>
</chartingToolkit:StackedColumnSeries>
Now I want it can create seriesDefinitions Dynamically using data-binding. like this:
//-------------DesignData File Begin (CostData.xaml)----------------//
<CostDemo_Model:CostData.CostDetail>
<CostDemo_Model:StackColumn title="plane">
<CostDemo_Model:StackColumn.fees>
<CostDemo_Model:PrjFee2 Fee="11" PrjName="costKind1"/>
<CostDemo_Model:PrjFee2 Fee="75" PrjName="costKind2"/>
<CostDemo_Model:PrjFee2 Fee="60" PrjName="costKind3"/>
<CostDemo_Model:PrjFee2 Fee="30" PrjName="costKind4"/>
<CostDemo_Model:PrjFee2 Fee="10" PrjName="costKind5"/>
</CostDemo_Model:StackColumn.fees>
</CostDemo_Model:StackColumn>
<CostDemo_Model:StackColumn title="Train">
<CostDemo_Model:StackColumn.fees>
<CostDemo_Model:PrjFee2 Fee="41" PrjName="costKind1"/>
<CostDemo_Model:PrjFee2 Fee="70" PrjName="costKind2"/>
<CostDemo_Model:PrjFee2 Fee="50" PrjName="costKind3"/>
<CostDemo_Model:PrjFee2 Fee="51" PrjName="costKind4"/>
<CostDemo_Model:PrjFee2 Fee="10" PrjName="costKind5"/>
</CostDemo_Model:StackColumn.fees>
</CostDemo_Model:StackColumn>
</CostDemo_Model:CostData.CostDetail>
//-------------DesignData File End (CostData.xaml)----------------//
//-------------View File Start(CostAnalysis.xaml)----------------//
<UserControl d:DataContext="{d:DesignData Source=/Model/Design/CostData.xaml}" >
<UserControl.Resources>
<toolkit:ObjectCollection x:Name="mySeries">
for(i=0; i<CostDetail.Count; i++){
<chartingToolkit:SeriesDefinition
DataContext="{Binding Path=CostDetail[i]}"
ItemsSource="{Binding fees}"
DependentValuePath="Fee"
IndependentValuePath="PrjName"
Title="{Binding title}"/>
}
</toolkit:ObjectCollection>
</UserControl.Resources>
<chartingToolkit:Chart>
<chartingToolkit:StackedColumnSeries SeriesDefinitions ={StaticResources mySeries}>
</chartingToolkit:StackedColumnSeries>
</chartingToolkit:Chart>
</UserControl>
//-------------View File End(CostAnalysis.xaml)----------------//
But I don't know how. Thanks for any help!