Пример #1
0
        private void SurfaceButton_ContactDown(object sender, ContactEventArgs e)
        {
            //SurfaceButton _bt = (SurfaceButton)sender;
            //_bt.po
            string stamp = Guid.NewGuid().ToString(); //guid to stamp the control name with
            stamp = stamp.Replace("-", ""); //remove the - from the guid

            //get the sender contact so we can get the orientation
            double o = e.Contact.GetOrientation(this);
            //Point p = e.Contact.GetPosition();

            //create the LibraryBar
            LibraryBar lb = new LibraryBar();
            lb.Width = 800;
            lb.Height = 200;
            lb.Rows = 1;
            lb.FontSize = 12;

            //need a binging item to get the xml resource out of the resource dictionary
            Binding items = new Binding();
            items.Source = FindResource("Source"); //Source is the XML data in the resource dict
            //items.XPath = "Entry"; //can use Xpath here to get the xml needed
            lb.SetBinding(ItemsControl.ItemsSourceProperty, items);
            lb.ItemTemplate = (DataTemplate)this.FindResource("BarItemTemplate"); //set the item template from the resource dict

            //register the library bar so we can find it later
            //NameScope.GetNameScope(this).RegisterName("fm1_anotherLb" + stamp, lb); //must call Registername to be able to use FindName later

            //Must create a new scatterview item to be added to the named scatter view in the XAML.
            ScatterViewItem svi = new ScatterViewItem();
            svi.Style = (Style)this.FindResource("LibraryControlInScatterViewItemContentStyle"); //Get the style for the scatterview item when using a surface library control (provided in SDK eg)
            //svi.Orientation = o + 90;

            svi.Content = lb;

            //register the scatterview item so we can find it later
            NameScope.GetNameScope(this).RegisterName("fm1_anotherSV" + stamp, svi); //must call Registername to be able to use FindName later

            DispatcherTimer timer = new DispatcherTimer();
            timer.Tag = _countDown; //store the count down in the tag of the timer so we can access it later
            timer.Interval = TimeSpan.FromSeconds(1);
            timer.Tick += new EventHandler(timer_Tick);
            timer.Start();

            //add the new timer and listview to the dictionary so we can get at it later
            myDictionary.Add(timer, svi);

            //work out the orinetation the user clicked from and the library bar to the correct side of the surface at the correct orientation.
            if (o <= 180)
            {
                svi.Orientation = 180;
                svi.Center = new Point(550, 150);
                //svi.Margin = new Thickness(458,284,44,0);
                svi.ClipToBounds = true;

                //add the library bar to the screen
                this.libraryScatterViewTop.Items.Add(svi);

            }
            else
            {
                svi.Orientation = 0;
                svi.Center = new Point(550, 600);
                svi.ClipToBounds = true;
                //add the library bar to the screen
                this.libraryScatterViewTop.Items.Add(svi); //bot
            }
        }
        private void addLibraryBar_ContactDown(object sender, ContactEventArgs e)
        {
            //SurfaceButton _bt = (SurfaceButton)sender;
            //_bt.po
            string stamp = Guid.NewGuid().ToString(); //guid to stamp the control name with
            stamp = stamp.Replace("-", ""); //remove the - from the guid

            //get the sender contact so we can get the orientation
            double o = e.Contact.GetOrientation(this);
            //Point p = e.Contact.GetPosition();

            //create the LibraryBar
            LibraryBar lb = new LibraryBar();
            lb.Width = 860;
            lb.Height = 250;
            lb.Rows = 1;

            //need a binging item to get the xml resource out of the resource dictionary
            Binding items = new Binding();
            items.Source = FindResource("Source"); //Source is the XML data in the resource dict
            //items.XPath = "Entry"; //can use Xpath here to get the xml needed
            lb.SetBinding(ItemsControl.ItemsSourceProperty, items);
            lb.ItemTemplate = (DataTemplate)this.FindResource("BarItemTemplate"); //set the item template from the resource dict

            //lb.AddHandler(SurfaceDragDrop.DragCompletedEvent,(OnShoppingListDragCompleted));

            //lb.PreviewContactDown  += OnShoppingListPreviewContactDown;
            //lb.PreviewContactChanged += OnShoppingListPreviewContactChanged;
            //lb.PreviewContactUp += OnShoppingListPreviewContactUp;
            //lb.PreviewMouseLeftButtonDown += OnShoppingListPreviewMouseLeftButtonDown;
            //lb.PreviewMouseMove += OnShoppingListPreviewMouseMove;
            //lb.PreviewMouseLeftButtonUp += OnShoppingListPreviewMouseLeftButtonUp;

            //register the library bar so we can find it later
            //NameScope.GetNameScope(this).RegisterName("fm1_anotherLb" + stamp, lb); //must call Registername to be able to use FindName later

            //Must create a new scatterview item to be added to the named scatter view in the XAML.
            ScatterViewItem svi = new ScatterViewItem();
            svi.Style = (Style)this.FindResource("LibraryControlInScatterViewItemContentStyle"); //Get the style for the scatterview item when using a surface library control (provided in SDK eg)
            svi.Orientation = o + 90;
            svi.Center = new Point(400, 400);
            svi.Content = lb;

            //register the scatterview item so we can find it later
            //NameScope.GetNameScope(this).RegisterName("fm1_anotherSV" + stamp, svi); //must call Registername to be able to use FindName later
            NameScope.GetNameScope(this).RegisterName("fm1_anotherSV", svi); //temp perm name

            DispatcherTimer timer = new DispatcherTimer();
            timer.Tag = _countDown; //store the count down in the tag of the timer so we can access it later
            timer.Interval = TimeSpan.FromSeconds(1);
            timer.Tick += new EventHandler(timer_Tick);
            timer.Start();

            //add the new timer and listview to the dictionary so we can get at it later
            myDictionary.Add(timer, svi);
            //add the library bar to the screen
            this.myScatterView.Items.Add(svi);
        }