Ejemplo n.º 1
0
        private void WindowsXamlHost_ChildChanged(object sender, EventArgs e)
        {
            var grid = (sender as WindowsXamlHost).Child as Windows.UI.Xaml.Controls.Grid;

            if (grid == null)
            {
                return;
            }

            var gridInkCanvas = new Windows.UI.Xaml.Controls.Grid();

            gridInkCanvas.Background = new Windows.UI.Xaml.Media.SolidColorBrush(Windows.UI.Colors.White);
            var inkCanvas = new Windows.UI.Xaml.Controls.InkCanvas();

            gridInkCanvas.Children.Add(inkCanvas);
            gridInkCanvas.SetValue(Windows.UI.Xaml.Controls.Grid.RowProperty, 1);
            inkCanvas.InkPresenter.InputDeviceTypes = CoreInputDeviceTypes.Mouse | CoreInputDeviceTypes.Pen | CoreInputDeviceTypes.Touch;


            var inkToolbar = new Windows.UI.Xaml.Controls.InkToolbar();

            inkToolbar.TargetInkCanvas = inkCanvas;
            inkToolbar.SetValue(Windows.UI.Xaml.Controls.Grid.RowProperty, 0);

            var firstRow = new Windows.UI.Xaml.Controls.RowDefinition();

            firstRow.Height = new Windows.UI.Xaml.GridLength(1, Windows.UI.Xaml.GridUnitType.Auto);
            var secondRow = new Windows.UI.Xaml.Controls.RowDefinition();

            secondRow.Height = new Windows.UI.Xaml.GridLength(1, Windows.UI.Xaml.GridUnitType.Star);
            grid.RowDefinitions.Add(firstRow);
            grid.RowDefinitions.Add(secondRow);

            grid.Children.Add(gridInkCanvas);
            grid.Children.Add(inkToolbar);
        }
            public GesturePage() :
                base(
                    "SemanticZoom",
                    "Pinch to semantic zoom",
                    "Semantic zoom is a new concept in our touch language. It’s designed to make it fast and fluid to jump within a list of content. Pinch two or more fingers on the screen  to change to an overview view.  Then tap or stretch the region or item you want to see more details for. For example, in People, pinch your contact list to see alphabet tiles (A, B, etc.), and then tap the desired letter to get back to the individual contact level (J for Jan).",
                    "Similar to when you use a mouse and click the “-” button, usually found in the lower-right corner.",
                    "Assets/pinch_sezo.png")
            {
                // Configure the app bar items for this page
                // GesturePageBase.Selected uses this._nonContextualItems to populate the global app bar when the page is selected.

                // Links button
                this._links["Doc: Guidelines for semantic zoom"] = new Uri("http://msdn.microsoft.com/en-us/library/windows/apps/hh465319.aspx");
                this._nonContextualItems.Add(GesturePageBase.CreateLinksAppBarButton(this._links));

                // Create the play area for this page
                var grid = new Windows.UI.Xaml.Controls.Grid();

                var row = new Windows.UI.Xaml.Controls.RowDefinition();

                row.Height = new Windows.UI.Xaml.GridLength(1, Windows.UI.Xaml.GridUnitType.Star);
                grid.RowDefinitions.Add(row);

                row        = new Windows.UI.Xaml.Controls.RowDefinition();
                row.Height = new Windows.UI.Xaml.GridLength(1, Windows.UI.Xaml.GridUnitType.Auto);
                grid.RowDefinitions.Add(row);

                var col = new Windows.UI.Xaml.Controls.ColumnDefinition();

                col.Width = new Windows.UI.Xaml.GridLength(2, Windows.UI.Xaml.GridUnitType.Star);
                grid.ColumnDefinitions.Add(col);

                col       = new Windows.UI.Xaml.Controls.ColumnDefinition();
                col.Width = new Windows.UI.Xaml.GridLength(1, Windows.UI.Xaml.GridUnitType.Star);
                grid.ColumnDefinitions.Add(col);

                var image = new Windows.UI.Xaml.Controls.Image
                {
                    Margin  = new Windows.UI.Xaml.Thickness(30, 30, 30, 30),
                    Source  = new Windows.UI.Xaml.Media.Imaging.BitmapImage(new Uri("ms-appx:///Assets/semantic_zoom.png")),
                    Stretch = Windows.UI.Xaml.Media.Stretch.Uniform
                };

                grid.Children.Add(image);
                Windows.UI.Xaml.Controls.Grid.SetColumn(image, 0);
                Windows.UI.Xaml.Controls.Grid.SetRow(image, 0);

                var textBlock = new Windows.UI.Xaml.Controls.TextBlock
                {
                    Style = App.Current.Resources["AppSubtitleTextStyle"] as Windows.UI.Xaml.Style,
                    Text  = "Pinch anywhere in this app to zoom out",
                    HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Center,
                    VerticalAlignment   = Windows.UI.Xaml.VerticalAlignment.Center,
                    TextWrapping        = Windows.UI.Xaml.TextWrapping.Wrap,
                    TextAlignment       = Windows.UI.Xaml.TextAlignment.Center
                };

                grid.Children.Add(textBlock);
                Windows.UI.Xaml.Controls.Grid.SetColumn(textBlock, 1);
                Windows.UI.Xaml.Controls.Grid.SetRow(textBlock, 0);

                this.Content = grid;
            }
Ejemplo n.º 3
0
        // Create constructor public MainPage.
        public MainPage()
        {
            // Necessary to instantiate this Page, add a stackPanel to this Page, et cetera.
            this.InitializeComponent();

            // Find width of app in view pixels and height between bottom of app and bottom of title bar in view pixels.
            double widthOfAppInViewPixels = Windows.UI.ViewManagement.ApplicationView.PreferredLaunchViewSize.Width;
            double heightBetweenBottomOfAppAndBottomOfTitleBarInViewPixels = Windows.UI.ViewManagement.ApplicationView.PreferredLaunchViewSize.Height;

            // Create a stackPanel.
            Windows.UI.Xaml.Controls.StackPanel stackPanel = new Windows.UI.Xaml.Controls.StackPanel();

            // Create a toolbar with width equal to the width of the app, height equal to 50 view pixels, and background color of light blue that has one row and three columns.
            Windows.UI.Xaml.Controls.Grid toolbar = new Windows.UI.Xaml.Controls.Grid();
            toolbar.Width      = widthOfAppInViewPixels;
            toolbar.Height     = 50;
            toolbar.Background = new Windows.UI.Xaml.Media.SolidColorBrush(Windows.UI.Colors.AliceBlue);
            Windows.UI.Xaml.Controls.RowDefinition row = new Windows.UI.Xaml.Controls.RowDefinition();
            toolbar.RowDefinitions.Add(row);
            Windows.UI.Xaml.Controls.ColumnDefinition columnForOpenImageButton         = new Windows.UI.Xaml.Controls.ColumnDefinition();
            Windows.UI.Xaml.Controls.ColumnDefinition columnForLoadBoundingBoxesButton = new Windows.UI.Xaml.Controls.ColumnDefinition();
            Windows.UI.Xaml.Controls.ColumnDefinition columnForTextboxForClassIndex    = new Windows.UI.Xaml.Controls.ColumnDefinition();
            Windows.UI.Xaml.Controls.ColumnDefinition columnForSaveLabeledImageButton  = new Windows.UI.Xaml.Controls.ColumnDefinition();
            Windows.UI.Xaml.Controls.ColumnDefinition columnForSaveLabelFileButton     = new Windows.UI.Xaml.Controls.ColumnDefinition();
            columnForOpenImageButton.Width         = new Windows.UI.Xaml.GridLength(widthOfAppInViewPixels * 3 / 7 / 2);
            columnForLoadBoundingBoxesButton.Width = new Windows.UI.Xaml.GridLength(widthOfAppInViewPixels * 3 / 7 / 2);
            columnForTextboxForClassIndex.Width    = new Windows.UI.Xaml.GridLength(widthOfAppInViewPixels / 7);
            columnForSaveLabeledImageButton.Width  = new Windows.UI.Xaml.GridLength(widthOfAppInViewPixels * 3 / 7 / 2);
            columnForSaveLabelFileButton.Width     = new Windows.UI.Xaml.GridLength(widthOfAppInViewPixels * 3 / 7 / 2);
            toolbar.ColumnDefinitions.Add(columnForOpenImageButton);
            toolbar.ColumnDefinitions.Add(columnForLoadBoundingBoxesButton);
            toolbar.ColumnDefinitions.Add(columnForTextboxForClassIndex);
            toolbar.ColumnDefinitions.Add(columnForSaveLabeledImageButton);
            toolbar.ColumnDefinitions.Add(columnForSaveLabelFileButton);

            // Add to toolbar's columnForOpenImageButton an "Open Image" button.
            Windows.UI.Xaml.Controls.Button openImageButton = new Windows.UI.Xaml.Controls.Button();
            openImageButton.Content = "Open Image";
            openImageButton.Height  = 40;
            Windows.UI.Xaml.Controls.Grid.SetRow(openImageButton, 0);
            Windows.UI.Xaml.Controls.Grid.SetColumn(openImageButton, 0);
            openImageButton.HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Center;
            openImageButton.Click += OpenImageButton_Click;
            toolbar.Children.Add(openImageButton);

            // Add to the toolbar's columnForLoadBoundingBoxesButton a "Load Bounding Boxes" button.
            Windows.UI.Xaml.Controls.Button loadBoundingBoxesButton = new Windows.UI.Xaml.Controls.Button();
            loadBoundingBoxesButton.Content = "Load Bounding Boxes";
            loadBoundingBoxesButton.Height  = 40;
            Windows.UI.Xaml.Controls.Grid.SetRow(loadBoundingBoxesButton, 0);
            Windows.UI.Xaml.Controls.Grid.SetColumn(loadBoundingBoxesButton, 1);
            loadBoundingBoxesButton.HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Center;
            loadBoundingBoxesButton.Click += LoadBoundingBoxesButton_Click;
            toolbar.Children.Add(loadBoundingBoxesButton);

            // Add to toolbar's columnForTextboxForClassIndex a labeled text box to store a user's choice of class index for an object they are about to bound.
            Windows.UI.Xaml.Controls.TextBlock textblockForClassIndex = new Windows.UI.Xaml.Controls.TextBlock();
            textblockForClassIndex.Text   = "Class Index: ";
            textblockForClassIndex.Height = 20;
            Windows.UI.Xaml.Controls.Grid.SetRow(textblockForClassIndex, 0);
            Windows.UI.Xaml.Controls.Grid.SetColumn(textblockForClassIndex, 2);
            toolbar.Children.Add(textblockForClassIndex);
            this.TextBoxForClassIndex        = new Windows.UI.Xaml.Controls.TextBox();
            this.TextBoxForClassIndex.Text   = "0";
            this.TextBoxForClassIndex.Width  = 40;
            this.TextBoxForClassIndex.Height = 40;
            Windows.UI.Xaml.Controls.Grid.SetRow(this.TextBoxForClassIndex, 0);
            Windows.UI.Xaml.Controls.Grid.SetColumn(this.TextBoxForClassIndex, 2);
            this.TextBoxForClassIndex.TextChanged += TextBoxForClassIndex_TextChanged;
            toolbar.Children.Add(this.TextBoxForClassIndex);

            // Add to toolbar's columnForSaveLabeledImageButton a "Save Labeled Image" button.
            Windows.UI.Xaml.Controls.Button saveLabeledImageButton = new Windows.UI.Xaml.Controls.Button();
            saveLabeledImageButton.Content = "Save Labeled Image";
            saveLabeledImageButton.Height  = 40;
            Windows.UI.Xaml.Controls.Grid.SetRow(saveLabeledImageButton, 0);
            Windows.UI.Xaml.Controls.Grid.SetColumn(saveLabeledImageButton, 3);
            saveLabeledImageButton.HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Center;
            saveLabeledImageButton.Click += SaveLabeledImageButton_Click;
            toolbar.Children.Add(saveLabeledImageButton);

            // Add to toolbar's columnForSaveLabelFileButton a "Save Label File" button.
            Windows.UI.Xaml.Controls.Button saveLabelFileButton = new Windows.UI.Xaml.Controls.Button();
            saveLabelFileButton.Content = "Save Label File";
            saveLabelFileButton.Height  = 40;
            Windows.UI.Xaml.Controls.Grid.SetRow(saveLabelFileButton, 0);
            Windows.UI.Xaml.Controls.Grid.SetColumn(saveLabelFileButton, 4);
            saveLabelFileButton.HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Center;
            saveLabelFileButton.Click += SaveLabelFileButton_Click;
            toolbar.Children.Add(saveLabelFileButton);

            // Add grid to the top of our stackPanel.
            stackPanel.Children.Add(toolbar);

            this.ImageCanvas                 = new Windows.UI.Xaml.Controls.Canvas();
            this.ImageCanvas.Width           = widthOfAppInViewPixels;
            this.ImageCanvas.Height          = heightBetweenBottomOfAppAndBottomOfTitleBarInViewPixels - toolbar.Height;
            this.ImageCanvas.PointerMoved   += new Windows.UI.Xaml.Input.PointerEventHandler(ImageCanvas_PointerMoved);
            this.ImageCanvas.PointerPressed += new Windows.UI.Xaml.Input.PointerEventHandler(ImageCanvas_PointerPressed);
            this.ImageCanvas.PointerExited  += new Windows.UI.Xaml.Input.PointerEventHandler(ImageCanvas_PointerExited);
            stackPanel.Children.Add(this.ImageCanvas);

            // Add stackPanel to the page defined in MainPage.xaml.
            page.Content = stackPanel;
        } // public MainPage