0
我有兩個WPF工具包圖表(列和餅圖)。使用DataTemplateSelector動態更改WPF工具包圖表類型
< - 柱形圖 - >
<DVC:Chart Name="mcChartPie" Title="{Binding ChartName}"
DataContext="{Binding SelectedChart}">
<DVC:Chart.Series>
<DVC:PieSeries ItemsSource="{Binding Columns}" Title="Some Chart"
IndependentValueBinding="{Binding Path=Name}" DependentValueBinding="{Binding
Path=Value}"></DVC:PieSeries>
</DVC:Chart.Series>
</DVC:Chart>
< - 餅圖 - >
<DVC:Chart Name="mcChart" Title="{Binding ChartName}"
DataContext="{Binding SelectedChart}" Style="{DynamicResource Info>
<DVC:Chart.Series>
<DVC:ColumnSeries ItemsSource="{Binding Columns}" Title="Some Chart"
IndependentValueBinding="{Binding Path=Name}" DependentValueBinding="{Binding
Path=Value}" Background="Black" AnimationSequence="FirstToLast" ></DVC:ColumnSeries>
</DVC:Chart.Series>
</DVC:Chart>
有一個組合框,其允許用戶選擇圖表類型。當用戶選擇「柱形圖類型」時,柱形圖模板應該是可見的,並且當用戶選擇「餅圖類型」時,餅圖模板應該是可見的。我怎麼能通過重寫DataTemplateSelector類中的SelectTemplate()方法來做到這一點?
唯一一個方法是創建2個用戶控件與2周的DataTemplates並切換它們。如何使用我在這個問題的答案中描述的'DataTemplateSelector'類:http://stackoverflow.com/questions/5309099/changing-the-view-for-a-viewmodel/5310213#5310213。 – vorrtex
謝謝!這真的很有幫助! – user1020800
你能寫出與系列類型相匹配的代碼嗎? –