Interaction logic for collection_listbox_item.xaml
Inheritance: System.Windows.Controls.UserControl
        public collection_listbox()
        {
            InitializeComponent();
            contributions.initialize(true, "", new ItemSelected(this.item_selected));

            collection_listbox_item cli = new collection_listbox_item();
            cli.img.Source = configurations.img_loading_image_pic;
            cli.img.Tag = null;
            //cli.percentage.Visibility = System.Windows.Visibility.Visible;
            cli.drag.Visibility = System.Windows.Visibility.Collapsed;
            this.contributions._list.Items.Add(cli);

            debug_canvas.Width = window_manager.main_canvas.ActualWidth;
            debug_canvas.Height = window_manager.main_canvas.ActualHeight;
            window_manager.main_canvas.Children.Add(debug_canvas);
            this.contributions.collection_list = true;
            this.Height = configurations.collection_listbox_height;

            this.Loaded += new RoutedEventHandler(collection_listbox_Loaded);
            //this.contributions.PreviewTouchUp += new EventHandler<System.Windows.Input.TouchEventArgs>(contributions_PreviewTouchUp);
            //this.contributions.PreviewTouchMove += new EventHandler<System.Windows.Input.TouchEventArgs>(contributions_PreviewTouchMove);
            //this.contributions.PreviewTouchDown += new EventHandler<System.Windows.Input.TouchEventArgs>(contributions_TouchDown);
        }
        void progress_changed(object sender, ProgressChangedEventArgs e)
        {
            this.contributions._list.Items.Dispatcher.BeginInvoke(DispatcherPriority.Normal,
               new System.Action(() =>
               {
                   try
                   {
                       loading_progress progress = (loading_progress)e.UserState;
                       //collection_listbox_item cli = (collection_listbox_item)this.contributions._list.Items[this.contributions._list.Items.Count - 1];
                       string progress_text = " (loading " + (e.ProgressPercentage).ToString() + " of " + progress.total + ")";
                       string[] title = this.parent.get_title().Split(new string[] { " (" }, StringSplitOptions.RemoveEmptyEntries);
                       this.parent.set_title(title[0] + progress_text);

                       if (progress.current_progress == 0)
                       {
                           this.contributions._list.Items.Clear();
                           for (int counter = 0; counter < progress.total; counter++)
                           {
                               collection_listbox_item c = new collection_listbox_item();
                               c.img.Source = configurations.img_loading_image_pic;
                               //c.img.GifSource = configurations.GetAbsoluteImagePath() + "loading1.gif";
                               c.img.Tag = null;
                               //c.percentage.Visibility = System.Windows.Visibility.Collapsed;
                               //c.percentage.Text = (e.ProgressPercentage).ToString() + " of " + progress.total + " contribution(s) downloaded.";
                               c.drag.Visibility = System.Windows.Visibility.Collapsed;
                               this.contributions._list.Items.Add(c);
                           }
                       }
                       else
                       {
                           ////load the item
                           collection_item i = progress.loaded_items[progress.current_progress - 1];
                           collection_listbox_item cli2 = new collection_listbox_item();

                           //Image img = new Image();
                           if (window_manager.thumbnails.ContainsKey(i._contribution.id))
                           {
                               cli2.img.Source = window_manager.thumbnails[i._contribution.id];
                               cli2.img.Tag = i;
                               cli2.drag.Source = configurations.img_drag_icon;
                           }
                           else
                           {
                               cli2.img.Source = configurations.img_not_found_image_pic;
                               cli2.img.Tag = null;
                           }
                           this.contributions._list.Items.RemoveAt(progress.current_progress - 1);
                           this.contributions._list.Items.Insert(progress.current_progress - 1, cli2);
                       }

                       this.contributions._list.Items.Refresh();
                   }
                   catch (Exception) { }
               }));
        }
        private bool start_drag(collection_listbox_item img, TouchDevice input)
        {
            if (img == null) return false;
            Image i2 = new Image();
            i2.Source = img.img.Source; i2.Stretch = Stretch.Uniform;
            ContentControl cursorVisual = new ContentControl();
            cursorVisual.Content = i2;
            cursorVisual.Style = (FindResource("CursorStyle") as Style);

            List<TouchDevice> devices = new List<TouchDevice>();
            devices.Add(input);
            foreach (TouchDevice touch in _list.TouchesCapturedWithin)
            {
                if (touch != input)
                {
                    devices.Add(touch);
                }
            }

            if (img.img.Tag == null) return false;

            collection_item item = (collection_item)img.img.Tag;
            log.WriteInteractionLog(4, "start dragging the contribution id: " + item._contribution.id, input);
            Microsoft.Surface.Presentation.SurfaceDragCursor startDragOkay =
                Microsoft.Surface.Presentation.SurfaceDragDrop.BeginDragDrop(
                  this._list,                 // The SurfaceListBox object that the cursor is dragged out from.
                  img,                        // The item object that is dragged from the drag source.
                  cursorVisual,               // The visual element of the cursor.
                  item,                       // The data associated with the cursor.
                  devices,                    // The input devices that start dragging the cursor.
                  DragDropEffects.Copy);      // The allowed drag-and-drop effects of the operation.

            return (startDragOkay != null);
        }