I have a bit of a unique setup on one page in my Windows Phone App that I'm having issues with and I'm not sure if it's an issue with the library I'm using or how I have the page setup. Long story short, on one page I have LongListSelector that displays a single Stacked Bar Chart (using OxyPlot) and then several Stack Panels with some TextBlocks (mostly sales information related to the Chart). What I want to do is when the user clicks on the Bar Chart the Chart will switch to a different Bar Chart (one has Month to date the other is Year to date) while the Stack Panel information stays the same. So far I've been able to get everything setup, but I get an Error when I tap on the Bar Chart stating "This PlotModel is already in use by some other PlotView control." and the app crashes. The way I was trying to switch between different charts was to just replace the ItemSource of the LLS with a different one, so I don't know if that's the problem or if it's just an issue with OxyPlot (from their forums it sounds like the Model doesn't re-render so I may just have to display both charts instead of just one). Here's what I have going on so far:
//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;
});