我的Windows Phone应用程序中的一个页面上有一些独特的设置,我遇到了问题,而且我不确定它是否是库I&#39的问题; m使用或如何设置页面。简而言之,在一个页面上,我有LongListSelector,它显示一个Stacked Bar Chart(使用OxyPlot),然后是几个带有一些TextBlocks的Stack Panels(主要是与Chart相关的销售信息)。我想要做的是当用户点击条形图时,图表将切换到另一个条形图(一个具有月份到期日,另一个是年初至今),而堆栈面板信息保持不变。到目前为止,我已经能够完成所有设置,但是当我点击条形图时,我得到一个错误,说明"这个PlotModel已经被其他一些PlotView控件使用了。"和应用程序崩溃。我试图在不同图表之间切换的方式是用不同的图表替换LLS的ItemSource,所以我不知道这是问题还是它只是一个问题使用OxyPlot(来自他们的论坛,听起来模型没有重新渲染,所以我可能只需要显示两个图表而不是一个)。这是我到目前为止所做的事情:
//first create model for MTD Commissions
PlotModel mtdModel = createMTDModel(mtdValue, mtdGoal);
//Create the Class Item for mtdGDC for LLS Source List
ServiceClasses.SalesGDCClass mtdItem = new ServiceClasses.SalesGDCClass();
mtdItem.model = mtdModel;
mtdItem.footerText = "Tap to view YTD";
mtdItem.version = 0;
//create model for YTD Commissions
PlotModel ytdModel = createYTDModel(ytdValue, (mtdGoal * 12));
//create class item for ytdGDC
ServiceClasses.SalesGDCClass ytdItem = new ServiceClasses.SalesGDCClass();
ytdItem.model = ytdModel;
ytdItem.footerText = "Tap to view MTD";
ytdItem.version = 1;
List<ServiceClasses.SalesItemsClass> mtdSource = new List<ServiceClasses.SalesItemsClass>();
ServiceClasses.SalesItemsClass mtdSalesItem = new ServiceClasses.SalesItemsClass()
{
type = "Sales",
key = "Sales",
salesItem = mtdItem
};
mtdSource.Add(mtdSalesItem);
//create YTD sales Item
List<ServiceClasses.SalesItemsClass> ytdSource = new List<ServiceClasses.SalesItemsClass>();
ServiceClasses.SalesItemsClass ytdSalesItem = new ServiceClasses.SalesItemsClass()
{
type = "Sales",
key = "Sales",
salesItem = ytdItem
};
ytdSource.Add(ytdSalesItem);
//add each transaction found for the last transaction section
foreach (var item in transactionList)
{
ServiceClasses.SalesItemsClass transactionItem = new ServiceClasses.SalesItemsClass()
{
type = "Transaction",
key = "Last 5 Transactions",
transactionItem = item
};
mtdSource.Add(transactionItem);
ytdSource.Add(transactionItem);
}
//create to source lists to switch between the MTD and YTD options
var mtdItemSource = StringKeyGroup<ServiceClasses.SalesItemsClass>.GetGroups(mtdSource, (ServiceClasses.SalesItemsClass c) => c.key);
var ytdItemSource = StringKeyGroup<ServiceClasses.SalesItemsClass>.GetGroups(ytdSource, (ServiceClasses.SalesItemsClass c) => c.key);
salesItemList.ItemsSource = mtdItemSource;
//add tap action to lls
salesItemList.SelectionChanged += (delegate(object sender, SelectionChangedEventArgs e)
{
//if selected item is null do nothing (such as when the page is loaded)
if (salesItemList.SelectedItem == null)
{
return;
}
ServiceClasses.SalesItemsClass selectedItem = (ServiceClasses.SalesItemsClass)salesItemList.SelectedItem;
if (selectedItem.type == "Sales")
{
Debug.WriteLine("the graph was selected");
//in here I was replacing the ItemSource but then it would crash
}
//reset the selected item value back to nothing
salesItemList.SelectedItem = null;
});
答案 0 :(得分:0)
渲染绘图后,无法替换ItemSource。所以,是的,这就是问题所在。我建议你删除/隐藏LineSeries的前一个实例,并在同一个PlotModel中创建一个新实例。
我认为有一个关于如何使线系列不可见的Oxyplot示例。