示例#1
0
        public BillSplitter()
        {
            InitializeComponent();

            HackyCommunicationClass.RegisterBillSplitter(this);
            recalculateBillSplitterTotals();

            Circle currentUserCircle = new Circle("currentUserId", new SolidColorBrush(Colors.Blue), "Me");
            Circle otherUserCircle   = new Circle("otherUserId", new SolidColorBrush(Colors.Red), "TG");
            Circle otherUser2Circle  = new Circle("otherUserId2", new SolidColorBrush(Colors.Green), "CD");

            CircleDock.Children.Insert(0, new Circle(currentUserCircle));
            CircleDock.Children.Insert(1, otherUserCircle);
            CircleDock.Children.Insert(2, otherUser2Circle);

            billSplitterComponent.Children.Clear();


            if (ChequePage.confirmedItems.Count() > 0)
            {
                foreach (Tuple <OrderedItem, List <string> > tuple in ChequePage.confirmedItems)
                {
                    billSplitterItemControl control = new billSplitterItemControl(tuple);
                    control.ItemName.Text  = tuple.Item1.itemDefinition.name;
                    control.ItemPrice.Text = "$" + (tuple.Item1.EffectiveCost() / 100.0).ToString("F");

                    if (tuple.Item2.Contains("currentUserId"))
                    {
                        control.DropArea.Children.Add(new Circle(currentUserCircle));
                    }
                    if (tuple.Item2.Contains("otherUserId"))
                    {
                        control.DropArea.Children.Add(new Circle(otherUserCircle));
                    }
                    if (tuple.Item2.Contains("otherUserId2"))
                    {
                        control.DropArea.Children.Add(new Circle(otherUser2Circle));
                    }

                    billSplitterComponent.Children.Add(control);
                }
            }
        }
示例#2
0
        private void Garbage_Drop(object sender, DragEventArgs e)
        {
            // If an element in the panel has already handled the drop,
            // the panel should not also handle it.
            if (e.Handled == false)
            {
                UIElement _element = (UIElement)e.Data.GetData("Object");

                if (sender != null && _element != null)
                {
                    StackPanel parent = (StackPanel)VisualTreeHelper.GetParent(_element);
                    if (parent.Name.Equals("DropArea"))
                    {
                        Circle circ = (Circle)_element;
                        billSplitterItemControl control = (billSplitterItemControl)((ContentPresenter)VisualTreeHelper.GetParent(VisualTreeHelper.GetParent(parent))).TemplatedParent;
                        control.itemReference.Item2.Remove(circ.userId);
                        parent.Children.Remove(circ);
                        recalculateBillSplitterTotals();
                    }
                }
            }
        }