public GraphControlBase()
		{
			Items = new UIElementCollection(this, this);

			mInternalItems = new GraphControlItems();
			AddLogicalChild(mInternalItems);
			AddVisualChild(mInternalItems);

			GraphItems = new GraphItemCollection();
			SubscribeToItemsUpdating(GraphItems);
			mInternalItems.ItemsSource = GraphItems;

			DataContextChanged += (s, e) =>
			{ mInternalItems.DataContext = e.NewValue; };
		}
示例#2
0
        private void UpdateGraph()
        {
            if (IsShowGraph == false)
            {
                return;
            }

            List <GraphModel> tempCollection = new List <GraphModel>();

            GraphDataCollection.Clear();

            // Initialize collection
            tempCollection.Add(new GraphModel(DateHelper.ToStringDate(DateHelper.GetDayOfWeek(_selectedDate, DayOfWeek.Monday))));
            tempCollection.Add(new GraphModel(DateHelper.ToStringDate(DateHelper.GetDayOfWeek(_selectedDate, DayOfWeek.Tuesday))));
            tempCollection.Add(new GraphModel(DateHelper.ToStringDate(DateHelper.GetDayOfWeek(_selectedDate, DayOfWeek.Wednesday))));
            tempCollection.Add(new GraphModel(DateHelper.ToStringDate(DateHelper.GetDayOfWeek(_selectedDate, DayOfWeek.Thursday))));
            tempCollection.Add(new GraphModel(DateHelper.ToStringDate(DateHelper.GetDayOfWeek(_selectedDate, DayOfWeek.Friday))));
            tempCollection.Add(new GraphModel(DateHelper.ToStringDate(DateHelper.GetDayOfWeek(_selectedDate, DayOfWeek.Saturday))));
            tempCollection.Add(new GraphModel(DateHelper.ToStringDate(DateHelper.GetDayOfWeek(_selectedDate, DayOfWeek.Sunday))));

            for (int i = 0; i < tempCollection.Count; i++)
            {
                var itemList = ItemCollection.Where(x => x.Date.Equals(tempCollection[i].Date));
                if (itemList.Count() == 0)
                {
                    continue;
                }

                foreach (var model in itemList)
                {
                    if (model.Type == ItemType.Income)
                    {
                        continue;
                    }

                    tempCollection[i].AddItem(model.Type, model.Amount);
                }
            }

            // Save to GraphItemCollection
            GraphItemCollection.Clear();
            var sortedCollection = tempCollection.OrderBy(x => x.Date);

            for (int i = 0; i < sortedCollection.Count(); i++)
            {
                GraphItemCollection.Add(sortedCollection.ElementAt(i));
            }
        }
		private void UnsubscribeFromItemsUpdating(GraphItemCollection collection)
		{
			if (collection == null)
				return;

			collection.CollectionChanged -= GraphItemsCollectionChanged;
			foreach (var item in collection)
				item.Updated -= ItemUpdated;
		}
		private void SubscribeToItemsUpdating(GraphItemCollection collection)
		{
			if (collection == null)
				return;

			collection.CollectionChanged += GraphItemsCollectionChanged;
			foreach (var item in collection)
				PrepareItem(item);
		}