Inheritance: DependencyObject, IUIElement, IUIElementOverrides
示例#1
0
        public static async Task <IRandomAccessStream> RenderToRandomAccessStream(this Windows.UI.Xaml.UIElement element)
        {
            RenderTargetBitmap rtb = new RenderTargetBitmap();
            await rtb.RenderAsync(element);

            var pixelBuffer = await rtb.GetPixelsAsync();

            var pixels = pixelBuffer.ToArray();

            // Useful for rendering in the correct DPI
            var displayInformation = DisplayInformation.GetForCurrentView();

            var stream  = new InMemoryRandomAccessStream();
            var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, stream);

            encoder.SetPixelData(BitmapPixelFormat.Bgra8,
                                 BitmapAlphaMode.Premultiplied,
                                 (uint)rtb.PixelWidth,
                                 (uint)rtb.PixelHeight,
                                 displayInformation.RawDpiX,
                                 displayInformation.RawDpiY,
                                 pixels);

            await encoder.FlushAsync();

            stream.Seek(0);

            return(stream);
        }
        public virtual void Add(UIElement control)
        {
            int rows = _grid.RowDefinitions.Count;
            _grid.RowDefinitions.Add(new RowDefinition());

            var textBlock = new TextBlock
            {
                Text = ListItemPrefix,
                Margin = new Thickness(0, 5, 0, 5),
                HorizontalAlignment = HorizontalAlignment.Center
            };
            Grid.SetColumn(textBlock, 0);
            Grid.SetRow(textBlock, rows);
            _grid.Children.Add(textBlock);

            if ((control is FrameworkElement) == false)
            {
                // UIElement can set column and row,
                // so use a border.
                var border = new Border
                {
                    Child = control
                };
                control = border;
            }
            Grid.SetColumn((FrameworkElement)control, 1);
            Grid.SetRow((FrameworkElement)control, rows);
            _grid.Children.Add(control);
        }
示例#3
0
        public ManipulationInputProcessor(Windows.UI.Input.GestureRecognizer gr, Windows.UI.Xaml.UIElement target, Windows.UI.Xaml.UIElement referenceframe)
        {
            this.gestureRecognizer = gr;
            this.element           = target;
            this.reference         = referenceframe;

            this.gestureRecognizer.GestureSettings =
                Windows.UI.Input.GestureSettings.Tap |
                Windows.UI.Input.GestureSettings.Hold | //hold must be set in order to recognize the press & hold gesture
                Windows.UI.Input.GestureSettings.RightTap |
                Windows.UI.Input.GestureSettings.ManipulationTranslateX |
                Windows.UI.Input.GestureSettings.ManipulationTranslateY |
                Windows.UI.Input.GestureSettings.ManipulationRotate |
                Windows.UI.Input.GestureSettings.ManipulationScale |
                Windows.UI.Input.GestureSettings.ManipulationTranslateInertia |
                Windows.UI.Input.GestureSettings.ManipulationRotateInertia |
                Windows.UI.Input.GestureSettings.ManipulationMultipleFingerPanning | //reduces zoom jitter when panning with multiple fingers
                Windows.UI.Input.GestureSettings.ManipulationScaleInertia;

            // Set up pointer event handlers. These receive input events that are used by the gesture recognizer.
            this.element.PointerCanceled += OnPointerCanceled;
            this.element.PointerPressed  += OnPointerPressed;
            this.element.PointerReleased += OnPointerReleased;
            this.element.PointerMoved    += OnPointerMoved;

            // Set up event handlers to respond to gesture recognizer output
            this.gestureRecognizer.Tapped                += OnTapped;
            this.gestureRecognizer.RightTapped           += OnRightTapped;
            this.gestureRecognizer.ManipulationStarted   += OnManipulationStarted;
            this.gestureRecognizer.ManipulationUpdated   += OnManipulationUpdated;
            this.gestureRecognizer.ManipulationCompleted += OnManipulationCompleted;
            InitializeTransforms();
        }
示例#4
0
        /// <summary>
        /// Displays the compatible scenarios and hides the non-compatible ones.
        /// If there are no supported devices, the scenarioContainer will be hidden and an error message
        /// will be displayed.
        /// </summary>
        /// <param name="scenarios">The key is the device type that the value, scenario, supports.</param>
        /// <param name="scenarioContainer">The container that encompasses all the scenarios that are specific to devices</param>
        public static void SetUpDeviceScenarios(Dictionary<DeviceType, UIElement> scenarios, UIElement scenarioContainer)
        {
            UIElement supportedScenario = null;

            if (EventHandlerForDevice.Current.IsDeviceConnected)
            {
                foreach (KeyValuePair<DeviceType, UIElement> deviceScenario in scenarios)
                {
                    // Enable the scenario if it's generic or the device type matches
                    if ((deviceScenario.Key == DeviceType.All)
                        || (deviceScenario.Key == Utilities.GetDeviceType(EventHandlerForDevice.Current.Device)))
                    {
                        // Make the scenario visible in case other devices use the same scenario and collapsed it.
                        deviceScenario.Value.Visibility = Visibility.Visible;

                        supportedScenario = deviceScenario.Value;
                    }
                    else if (deviceScenario.Value != supportedScenario)
                    {
                        // Don't hide the scenario if it is supported by the current device and is shared by other devices

                        deviceScenario.Value.Visibility = Visibility.Collapsed;
                    }
                }
            }

            if (supportedScenario == null)
            {
                // Hide the container so that common elements shared across scenarios are also hidden
                scenarioContainer.Visibility = Visibility.Collapsed;

                NotifyDeviceNotConnected();
            }
        }
        public void Initialize(UIElement host, CompositionImage sourceElement, object payload)
        {
            _host = host;
            _parent = host;
            _payload = payload;

            // Make a copy of the sourceElement's sprite so we can hand it off to the next page
            SpriteVisual sourceSprite = sourceElement.SpriteVisual;
            Compositor compositor = sourceSprite.Compositor;
            _sprite = compositor.CreateSpriteVisual();
            _sprite.Size = sourceSprite.Size;
            _sprite.Brush = sourceElement.SurfaceBrush;

            // We're going to use the backing surface, make sure it doesn't get released
            sourceElement.SharedSurface = true;

            // Determine the offset from the host to the source element used in the transition
            GeneralTransform coordinate = sourceElement.TransformToVisual(_parent);
            Point position = coordinate.TransformPoint(new Point(0, 0));

            // Set the sprite to that offset relative to the host
            _sprite.Offset = new Vector3((float)position.X, (float)position.Y, 0);

            // Set the sprite as the content under the host
            ElementCompositionPreview.SetElementChildVisual(_parent, _sprite);
        }
示例#6
0
        public virtual void SetPrintContent(UIElement content)
        {
            if (content == null)
                return;

            PrintContent = content;
        }
        /// <summary>
        /// Shows a popup dialog for the specified model relative to the <paramref name="placementTarget"/>.
        /// </summary>
        /// <param name="rootModel">The root model.</param>
        /// <param name="placementTarget">The placement target.</param>
        /// <param name="viewSettings">The optional dialog settings.</param> 
        public void ShowFlyout(object rootModel, UIElement placementTarget, IDictionary<string, object> viewSettings = null) {
            var view = ViewLocator.LocateForModel(rootModel, null, null);
            ViewModelBinder.Bind(rootModel, view, null);

            var flyout = new Flyout
                {
                    Content = view,
                    PlacementTarget = placementTarget,
                };

            ApplySettings(flyout, viewSettings);
            flyout.IsOpen = true;

            var deactivator = rootModel as IDeactivate;
            if (deactivator != null) {
                EventHandler<object> closed = null;
                closed = (s, e) => {
                    deactivator.Deactivate(true);
                    flyout.Closed -= closed;
                };

                flyout.Closed += closed;
            }

            var activator = rootModel as IActivate;
            if (activator != null) {
                activator.Activate();
            }
        }
 private void DoRenderText()
 {
     if (RenderSuspended)
     {
         return;
     }
     try
     {
         var map = cachedMap;
         if (lastMapId != mapId && map != null)
         {
             lastMapId = mapId;
             var renderer = new XamlCanvasTextRender2Renderer(ControlCallback);
             var textRender = renderer.Render(map);
             textRender.HorizontalAlignment = HorizontalAlignment.Left;
             textRender.VerticalAlignment = VerticalAlignment.Top;
             var a = new UIElement[1];
             a[0] = textRender;
             ChildUpdateHelper.UpdateChildren(MainGrid.Children, a);
         }
     }
     catch
     {
         // ignored
     }
 }
        // Unused and untested 
        public static void ShowMessage(string message, UIElement placementTarget, PlacementMode placementMode=PlacementMode.Top)
        {
            var f = new Callisto.Controls.Flyout();

            var b = new Border()
                           {
                               Width = 300,
                               Height = 125
                           };

            TextBlock tb = new TextBlock();
            tb.HorizontalAlignment = HorizontalAlignment.Center;
            tb.VerticalAlignment = VerticalAlignment.Center;
            tb.TextWrapping = TextWrapping.Wrap;
            tb.FontSize = 12f;
            tb.Text = message;

            b.Child = tb;

            f.Content = b;

            f.Placement = placementMode;
            f.PlacementTarget = placementTarget;

            f.IsOpen = true;
        }
        /// <summary>
        /// Invoked whenever application code or internal processes (such as a rebuilding layout pass) call ApplyTemplate.
        /// In simplest terms, this means the method is called just before a UI element displays in your app.
        /// Override this method to influence the default post-template logic of a class.
        /// </summary>
        protected override void OnApplyTemplate()
        {
            // Border
            this.border = this.GetTemplateChild(BorderPartName) as Border;
            if (this.border != null)
            {
                this.border.ManipulationStarted += Border_ManipulationStarted;
                this.border.ManipulationDelta += Border_ManipulationDelta;
                this.border.ManipulationCompleted += Border_ManipulationCompleted;
                this.border.Tapped += Border_Tapped;
                this.border.PointerEntered += Border_PointerEntered;

                // Move Canvas properties from control to border.
                Canvas.SetLeft(this.border, Canvas.GetLeft(this));
                Canvas.SetLeft(this, 0);
                Canvas.SetTop(this.border, Canvas.GetTop(this));
                Canvas.SetTop(this, 0);

                // Move Margin to border.
                this.border.Padding = this.Margin;
                this.Margin = new Thickness(0);
            }
            else
            {
                // Exception
                throw new Exception("Floating Control Style has no Border.");
            }

            // Overlay
            this.overlay = GetTemplateChild(OverlayPartName) as UIElement;

            this.Loaded += Floating_Loaded;
        }
        private async Task Run(CancellationToken ct)
        {
            MyContent = new MyNestedContent()
            {
                MyProperty = 42
            };
            View content = null;

            while (!ct.IsCancellationRequested)
            {
                if (rootGrid.Children.Any())
                {
                    content = rootGrid.Children.First() as UIElement;
                    rootGrid.Children.Remove(content);
                }
                else
                {
                    rootGrid.Children.Add(content);
                }

                await Task.Delay(1000);
            }

            if (rootGrid.Children.Count == 0 && content != null)
            {
                rootGrid.Children.Add(content);
            }
        }
示例#12
0
 public void Delete(ref UIElement surface)
 {
     if (!IsVisible)
     {
         DelayedDelete(60, surface, _rootElement);
     }
 }
示例#13
0
        public static double DistanceFromTop(this ScrollViewer scrollViewer, UIElement element)
        {
            var transform = element.TransformToVisual(scrollViewer);
            var position = transform.TransformPoint(new Point(0, 0));

            return position.Y;
        }
示例#14
0
		public RemedyOptions()
		{
            // Main function.
            this.InitializeComponent();
            temp = ResizePanel;
            tempPanel.Children.Remove(ResizePanel);
		}
 public static void OnPointerPressed(UIElement sender, TouchSliderC slider, PointerRoutedEventArgs e)
 {
     sender.CapturePointer(e.Pointer);
     _lastPoint = e.GetCurrentPoint(slider);
     _isDragActive = true;
     e.Handled = true;
 }
示例#16
0
        private void InjectPropertiesForChildViews(IComponentContext context, IPresentationBusConfiguration bus, UIElement uiElement)
        {
            var userControl = uiElement as UserControl;
            if (userControl != null)
            {
                InjectProperties(context, bus, userControl.Content);
                return;
            }

            var panel = uiElement as Panel;
            if (panel != null)
            {
                foreach (var child in panel.Children)
                {
                    InjectProperties(context, bus, child);
                }
                return;
            }

            var contentControl = uiElement as ContentControl;
            if (contentControl != null)
            {
                InjectProperties(context, bus, contentControl.Content as UIElement);
                return;
            }
        }
示例#17
0
        public InputEvents(CoreWindow window, UIElement inputElement, TouchQueue touchQueue)
        {
            _touchQueue = touchQueue;

            // The key events are always tied to the window as those will
            // only arrive here if some other control hasn't gotten it.
            window.KeyDown += CoreWindow_KeyDown;
            window.KeyUp += CoreWindow_KeyUp;
            window.VisibilityChanged += CoreWindow_VisibilityChanged;

            if (inputElement != null)
            {
                // If we have an input UIElement then we bind input events
                // to it else we'll get events for overlapping XAML controls.
                inputElement.PointerPressed += UIElement_PointerPressed;
                inputElement.PointerReleased += UIElement_PointerReleased;
                inputElement.PointerCanceled += UIElement_PointerReleased;
                inputElement.PointerMoved += UIElement_PointerMoved;
                inputElement.PointerWheelChanged += UIElement_PointerWheelChanged;
            }
            else
            {
                // If we only have a CoreWindow then use it for input events.
                window.PointerPressed += CoreWindow_PointerPressed;
                window.PointerReleased += CoreWindow_PointerReleased;
                window.PointerMoved += CoreWindow_PointerMoved;
                window.PointerWheelChanged += CoreWindow_PointerWheelChanged;
            }
        }
示例#18
0
        async System.Threading.Tasks.Task<Windows.Storage.StorageFile> CaptureAndSave(UIElement element)
        {
            // capture
            var bitmap = new Windows.UI.Xaml.Media.Imaging.RenderTargetBitmap();
            await bitmap.RenderAsync(element);
            var picker = new Windows.Storage.Pickers.FileSavePicker
            {
                SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary,
                FileTypeChoices = { { "JPEG", new[] { ".jpg" } } },
                SuggestedFileName = "Image",
                DefaultFileExtension = ".jpg",
                CommitButtonText = "Save",
            };

            // save
            var file = await picker.PickSaveFileAsync();
            using (var stream = await file.OpenStreamForWriteAsync())
            {

                var pixel = await bitmap.GetPixelsAsync();
                var dpi = Windows.Graphics.Display.DisplayInformation.GetForCurrentView().LogicalDpi;
                var random = stream.AsRandomAccessStream();
                var jpg = Windows.Graphics.Imaging.BitmapEncoder.JpegEncoderId;
                var encoder = await Windows.Graphics.Imaging.BitmapEncoder.CreateAsync(jpg, random);
                var format = Windows.Graphics.Imaging.BitmapPixelFormat.Bgra8;
                var alpha = Windows.Graphics.Imaging.BitmapAlphaMode.Ignore;
                var width = (uint)bitmap.PixelWidth;
                var height = (uint)bitmap.PixelHeight;
                encoder.SetPixelData(format, alpha, width, height, dpi, dpi, pixel.ToArray());
                await encoder.FlushAsync();
            }
            return file;
        }
示例#19
0
            public Point GetPosition(object?relativeTo)
            {
                CGPoint windowLocation = new CGPoint(0.0, 0.0);

                if (_macOSDraggingInfo != null && _window.ContentView is { } contentView)
                {
                    windowLocation = contentView.ConvertPointFromView(_macOSDraggingInfo.DraggingLocation, null);
                }
                var rawPosition = new Point(windowLocation.X, windowLocation.Y);

                if (relativeTo is null)
                {
                    return(rawPosition);
                }

                if (relativeTo is UIElement elt)
                {
                    var eltToRoot = UIElement.GetTransform(elt, null);
                    var rootToElt = eltToRoot.Inverse();

                    return(rootToElt.Transform(rawPosition));
                }

                throw new InvalidOperationException("The relative to must be a UIElement.");
            }
        public AdnGestureManager(
            UIElement window, 
            AdnRenderer renderer)
        {
            _window = window;

            _renderer = renderer;

            _pointerMode = PointerMode.kIdleMode;

            _accumulator = new ValueAccumulator(
                -30.0 * 1000.0 / 5.0,
                -100.0 * 1000.0 / 5.0,
                -5.0 * 1000.0 / 5.0);

            _pointers = new Dictionary<uint, PointerPoint>();

            window.PointerMoved += OnPointerMoved;
            window.PointerPressed += OnPointerPressed;
            window.PointerReleased += OnPointerReleased;
            window.PointerWheelChanged += OnPointerWheelChanged;

            _gr = new GestureRecognizer();

            _gr.GestureSettings =
              GestureSettings.Tap |
              GestureSettings.Drag |
              GestureSettings.DoubleTap |
              GestureSettings.ManipulationScale;

            _gr.Tapped += OnTapped;
            _gr.ManipulationStarted += OnManipulationStarted;
            _gr.ManipulationUpdated += OnManipulationUpdated;
            _gr.ManipulationCompleted += OnManipulationCompleted;
        }
 private void RunIfSelected(UIElement element, Action action)
 {
     if (ChartsList.SelectedItem == element)
     {
         action.Invoke();
     }
 }
 public static ContainerVisual GetVisual(UIElement element)
 {
     var hostVisual = ElementCompositionPreview.GetElementVisual(element);
     ContainerVisual root = hostVisual.Compositor.CreateContainerVisual();
     ElementCompositionPreview.SetElementChildVisual(element, root);
     return root;
 }
示例#23
0
        public async Task<string> RenderToBase64(UIElement element)
        {
            RenderTargetBitmap rtb = new RenderTargetBitmap();
            await rtb.RenderAsync(element);

            var pixelBuffer = await rtb.GetPixelsAsync();
            var pixels = pixelBuffer.ToArray();

            // Useful for rendering in the correct DPI
            var displayInformation = DisplayInformation.GetForCurrentView();

            var stream = new InMemoryRandomAccessStream();
            var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, stream);
            encoder.SetPixelData(BitmapPixelFormat.Bgra8,
                                 BitmapAlphaMode.Premultiplied,
                                 (uint)rtb.PixelWidth,
                                 (uint)rtb.PixelHeight,
                                 displayInformation.RawDpiX,
                                 displayInformation.RawDpiY,
                                 pixels);

            await encoder.FlushAsync();
            stream.Seek(0);

            // read bytes
            var bytes = new byte[stream.Size];
            await stream.AsStream().ReadAsync(bytes, 0, bytes.Length);

            // create base64
            return Convert.ToBase64String(bytes);
        }
 public void Add(UIElement control)
 {
     Add(new InlineUIContainer
     {
         Child = control
     });
 }
示例#25
0
        public ManipulationInputProcessor(Windows.UI.Input.GestureRecognizer gr, Windows.UI.Xaml.UIElement target, Windows.UI.Xaml.UIElement referenceframe)
        {
            this.gestureRecognizer = gr;
            this.element = target;
            this.reference = referenceframe;

            this.gestureRecognizer.GestureSettings =
                Windows.UI.Input.GestureSettings.Tap |
                Windows.UI.Input.GestureSettings.Hold | //hold must be set in order to recognize the press & hold gesture
                Windows.UI.Input.GestureSettings.RightTap |
                Windows.UI.Input.GestureSettings.ManipulationTranslateX |
                Windows.UI.Input.GestureSettings.ManipulationTranslateY |
                Windows.UI.Input.GestureSettings.ManipulationRotate |
                Windows.UI.Input.GestureSettings.ManipulationScale |
                Windows.UI.Input.GestureSettings.ManipulationTranslateInertia |
                Windows.UI.Input.GestureSettings.ManipulationRotateInertia |
                Windows.UI.Input.GestureSettings.ManipulationMultipleFingerPanning | //reduces zoom jitter when panning with multiple fingers
                Windows.UI.Input.GestureSettings.ManipulationScaleInertia;

            // Set up pointer event handlers. These receive input events that are used by the gesture recognizer.
            this.element.PointerCanceled += OnPointerCanceled;
            this.element.PointerPressed += OnPointerPressed;
            this.element.PointerReleased += OnPointerReleased;
            this.element.PointerMoved += OnPointerMoved;

            // Set up event handlers to respond to gesture recognizer output
            this.gestureRecognizer.Tapped += OnTapped;
            this.gestureRecognizer.RightTapped += OnRightTapped;
            this.gestureRecognizer.ManipulationStarted += OnManipulationStarted;
            this.gestureRecognizer.ManipulationUpdated += OnManipulationUpdated;
            this.gestureRecognizer.ManipulationCompleted += OnManipulationCompleted;
            InitializeTransforms();
        }
示例#26
0
        /// <summary>
        /// Start of the Drag and Drop operation: we set some content and change the DragUI
        /// depending on the selected options
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private async void SourceGrid_DragStarting(Windows.UI.Xaml.UIElement sender, Windows.UI.Xaml.DragStartingEventArgs args)
        {
            args.Data.SetText(SourceTextBox.Text);
            if ((bool)DataPackageRB.IsChecked)
            {
                // Standard icon will be used as the DragUIContent
                args.DragUI.SetContentFromDataPackage();
            }
            else if ((bool)CustomContentRB.IsChecked)
            {
                // Generate a bitmap with only the TextBox
                // We need to take the deferral as the rendering won't be completed synchronously
                var deferral = args.GetDeferral();
                var rtb      = new RenderTargetBitmap();
                await rtb.RenderAsync(SourceTextBox);

                var buffer = await rtb.GetPixelsAsync();

                var bitmap = SoftwareBitmap.CreateCopyFromBuffer(buffer,
                                                                 BitmapPixelFormat.Bgra8,
                                                                 rtb.PixelWidth,
                                                                 rtb.PixelHeight,
                                                                 BitmapAlphaMode.Premultiplied);
                args.DragUI.SetContentFromSoftwareBitmap(bitmap);
                deferral.Complete();
            }
            // else just show the dragged UIElement
        }
 private void LostFocusHandler(object sender, RoutedEventArgs e)
 {
     if (lastFocusedElement == (UIElement)sender)
     {
         lastFocusedElement = null;
     }
 }
示例#28
0
        private void buttonScanCustom_Click(object sender, RoutedEventArgs e)
        {
            //Get our UIElement from the MainPage.xaml (this) file 
            // to use as our custom overlay
            if (customOverlayElement == null)
            {
                customOverlayElement = this.customOverlay.Children[0];
                this.customOverlay.Children.RemoveAt(0);
            }

            //Wireup our buttons from the custom overlay
            this.buttonCancel.Click += (s, e2) =>
            {
                scanner.Cancel();
            };
            this.buttonFlash.Click += (s, e2) =>
            {
                scanner.ToggleTorch();
            };

            //Set our custom overlay and enable it
            scanner.CustomOverlay = customOverlayElement;
            scanner.UseCustomOverlay = true;

            //Start scanning
            scanner.Scan().ContinueWith(t =>
            {
                if (t.Result != null)
                    HandleScanResult(t.Result);
            });
        }
示例#29
0
 public static void SetContent(this Popup popup, UIElement newContent)
 {
     var contentControl = popup.Child as ContentControl;
     contentControl.Height = Window.Current.Bounds.Height;
     contentControl.Width = Window.Current.Bounds.Width;
     contentControl.Content = newContent;
 }
        private void ShowContextMenu(UIElement target, Point offset) {
            var MyFlyout = this.Resources["rjlMenuFlyout"] as MenuFlyout;

            System.Diagnostics.Debug.WriteLine("MenuFlyout shown '{0}', '{1}'", target, offset);

            MyFlyout.ShowAt(target, offset);
        }
示例#31
0
        /// <summary>
        /// Set up Continuity by hooking continuing Visuals to root Frame and getting global co-ordinates so that Visual seems to remain on the same location even though pages change and local coordinate space changes as well. 
        /// </summary>
        /// <param name="containerVisual">Container Visual which contains visual that needs to continue between pages</param>
        /// <param name="hostElement">UIElement which the Visual is hosted in</param>
        /// <param name="newContainerVisual">new ContainerVisual after re-parent of sprite Visual to root.</param>
        public static void SetupContinuity(ContainerVisual containerVisual,UIElement HostElement, out ContainerVisual newContainerVisual)
        {
            if (null == containerVisual || null == HostElement)
            {
                newContainerVisual = null;
                return;
            }
            Frame rootFrame = Window.Current.Content as Frame;
            Visual rootVisual = ElementCompositionPreview.GetElementVisual(rootFrame);
            Compositor compositor = rootVisual.Compositor;
            //remove element from current tree 
            var visualChild = containerVisual.Children.FirstOrDefault();
            containerVisual.Children.Remove(visualChild);

            //create temp container to add the visual to the root 
            ContainerVisual tempContainer = compositor.CreateContainerVisual();
            tempContainer.Children.InsertAtTop(visualChild);
            //Get location of visual as compared to root frame. 
            var coordinate = HostElement.TransformToVisual(rootFrame);
            var position = coordinate.TransformPoint(new Point(0, 0));
            //set the location of container visual to same visual location but now root as the parent.
            tempContainer.Offset = new System.Numerics.Vector3((float)position.X, (float)position.Y, 0);
            visualChild.Offset = new System.Numerics.Vector3(0, 0, 0);

            //add container with sprite to the window of app
            ElementCompositionPreview.SetElementChildVisual(rootFrame, tempContainer);
            containerVisual = null;
            newContainerVisual = tempContainer;
        }
示例#32
0
 public static Edge GetEdge(UIElement element)
 {
     if (element == null)
     {
         throw new ArgumentNullException("element");
     }
     return (Edge)element.GetValue(EdgeProperty);
 }
        public void SetContent(UIElement content)
        {
            rootGrid.Children.Add(content);
            Grid.SetRow((FrameworkElement)content, 1);

            coreTitleBar.ExtendViewIntoTitleBar = true;
            Window.Current.SetTitleBar(TitleBar);
        }
示例#34
0
        public void InitializeUI(Windows.UI.Xaml.UIElement rootForPointerEvents, Windows.UI.Xaml.UIElement rootOfLayout)
        {
            _root       = rootForPointerEvents;
            _rootParent = rootOfLayout;

            _appWidth  = (float)((FrameworkElement)_root).ActualWidth;
            _appHeight = (float)((FrameworkElement)_root).ActualHeight;
        }
示例#35
0
 public static void SetEdge(UIElement element, Edge edge)
 {
     if (element == null)
     {
         throw new ArgumentNullException("element");
     }
     element.SetValue(EdgeProperty, edge);
 }
示例#36
0
        public Settings()
        {
            this.InitializeComponent();

            visibleContent = BasicPreferencesGridView;

            SetupLanguages();
        }
示例#37
0
 private void RootCanas_ContextRuested(Windows.UI.Xaml.UIElement sender, ContextRequestedEventArgs args)
 {
     if (args.TryGetPosition(RootCanvas, out Point p))
     {
         args.Handled = true;
         PostEvent(DrawEvent.ContextMenu);
     }
 }
示例#38
0
        /// <summary>
        /// Adds the specified element to the canvas.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="clipOffsetX">The clip offset X.</param>
        /// <param name="clipOffsetY">The clip offset Y.</param>
        private void Add(Windows.UI.Xaml.UIElement element, double clipOffsetX = 0, double clipOffsetY = 0)
        {
            if (this.clip)
            {
                this.ApplyClip(element, clipOffsetX, clipOffsetY);
            }

            this.canvas.Children.Add(element);
        }
示例#39
0
        public void InitializeUI(Windows.UI.Xaml.UIElement rootForPointerEvents, Windows.UI.Xaml.UIElement rootOfLayout)
        {
            _root       = rootForPointerEvents;
            _rootParent = rootOfLayout;


            _updateDimensions(((FrameworkElement)_root).ActualWidth, ((FrameworkElement)_root).ActualHeight);


            _pathD2DConverter = new SumoNinjaMonkey.Framework.Lib.PathToD2DPathGeometryConverter();
        }
示例#40
0
        public void GestureInputProcessor(Windows.UI.Input.GestureRecognizer gr, Windows.UI.Xaml.UIElement target)
        {
            this.gestureRecognizer = gr;
            //Targeted Ui element to be performing gestures on it.
            this.element = target;

            //Enable gesture settings for Tap,Hold,RightTap,CrossSlide
            this.gestureRecognizer.GestureSettings =
                Windows.UI.Input.GestureSettings.ManipulationTranslateX |
                Windows.UI.Input.GestureSettings.ManipulationTranslateY;

            // Set up pointer event handlers. These receive input events that are used by the gesture recognizer.
            this.element.PointerCanceled += OnPointerCanceled;
            this.element.PointerPressed  += OnPointerPressed;
            this.element.PointerReleased += OnPointerReleased;
            this.element.PointerMoved    += OnPointerMoved;

            gestureRecognizer.ManipulationCompleted += gestureRecognizer_ManipulationCompleted;
            gestureRecognizer.ManipulationStarted   += gestureRecognizer_ManipulationStarted;
        }
示例#41
0
        public GestureInputProcessor(Windows.UI.Input.GestureRecognizer gr, Windows.UI.Xaml.UIElement target)
        {
            this.gestureRecognizer = gr;
            this.element           = target;

            this.gestureRecognizer.GestureSettings =
                Windows.UI.Input.GestureSettings.Tap |
                Windows.UI.Input.GestureSettings.Hold | //hold must be set in order to recognize the press & hold gesture
                Windows.UI.Input.GestureSettings.RightTap;

            // Set up pointer event handlers. These receive input events that are used by the gesture recognizer.
            this.element.PointerCanceled += OnPointerCanceled;
            this.element.PointerPressed  += OnPointerPressed;
            this.element.PointerReleased += OnPointerReleased;
            this.element.PointerMoved    += OnPointerMoved;

            // Set up event handlers to respond to gesture recognizer output
            this.gestureRecognizer.Tapped      += OnTapped;
            this.gestureRecognizer.RightTapped += OnRightTapped;
        }
示例#42
0
        /// <summary>
        /// Enumerates all the children for a specified view group.
        /// </summary>
        /// <param name="view">The view group to get the children from</param>
        /// <param name="maxDepth">The depth to stop looking for children.</param>
        /// <returns>A lazy enumerable of views</returns>
        public static IEnumerable <_View> EnumerateAllChildren(this _ViewGroup view, int maxDepth = 20)
        {
            var children = view.GetChildren().OfType <_ViewGroup>();

            foreach (var child in children)
            {
                yield return(child);

                if (maxDepth > 0)
                {
                    if (child is _ViewGroup childGroup)
                    {
                        foreach (var subResult in childGroup.EnumerateAllChildren(maxDepth - 1))
                        {
                            yield return(subResult);
                        }
                    }
                }
            }
        }
示例#43
0
            /// <inheritdoc />
            public Point GetPosition(object?relativeTo)
            {
                var rawWpfPosition = _wpfArgs.GetPosition(WpfHost.Current);
                var rawPosition    = new Point(rawWpfPosition.X, rawWpfPosition.Y);

                if (relativeTo is null)
                {
                    return(rawPosition);
                }

                if (relativeTo is UIElement elt)
                {
                    var eltToRoot = UIElement.GetTransform(elt, null);
                    Matrix3x2.Invert(eltToRoot, out var rootToElt);

                    return(rootToElt.Transform(rawPosition));
                }

                throw new InvalidOperationException("The relative to must be a UIElement.");
            }
示例#44
0
        void AddToNativeParent(View parent, xaml.UIElement nativeChild, float top, float left)
        {
            var nativeParent = parent?.Native() as xaml.UIElement;

            if (nativeParent is controls.Border wrapper)
            {
                nativeParent = wrapper.Child;
            }

            // High concurrency. Already disposed:
            if (parent == null || parent.IsDisposed || nativeParent == null || nativeChild == null)
            {
                return;
            }

            try
            {
                if (nativeParent is controls.Panel panel)
                {
                    panel.Children.Add(nativeChild);
                }
                else if (nativeParent is controls.ScrollViewer scroller)
                {
                    (scroller.Content as controls.Panel)?.Children.Add(nativeChild);
                }
                else
                {
                    throw new Exception(nativeParent.GetType().Name +
                                        " is not a supported container for rendering.");
                }
            }
            catch (System.Runtime.InteropServices.COMException)
            {
                /*No logging is needed. Is this a strange random UWP bug ?*/
            }

            controls.Canvas.SetLeft(nativeChild, left);
            controls.Canvas.SetTop(nativeChild, top);
        }
示例#45
0
		/// <summary>
		/// Enumerates all the children for a specified view group.
		/// </summary>
		/// <param name="view">The view group to get the children from</param>
		/// <param name="maxDepth">The depth to stop looking for children.</param>
		/// <returns>A lazy enumerable of views</returns>
		public static IEnumerable<_View> EnumerateAllChildren(this _ViewGroup view, int maxDepth = 20)
		{
			var children = view.GetChildren().OfType<UIElement>();

			foreach (var sub in children)
			{
				yield return sub;

				if (maxDepth > 0)
				{
					var childGroup = sub as _ViewGroup;

					if (childGroup != null)
					{
						foreach (var subResult in childGroup.EnumerateAllChildren(maxDepth - 1))
						{
							yield return subResult;
						}
					}
				}
			}
		}
示例#46
0
        /// <summary>
        /// Enumerates all the children for a specified view group.
        /// </summary>
        /// <param name="view">The view group to get the children from</param>
        /// <param name="selector">The selector function</param>
        /// <param name="maxDepth">The depth to stop looking for children.</param>
        /// <returns>A lazy enumerable of views</returns>
        public static IEnumerable <_View> EnumerateAllChildren(this _ViewGroup view, Func <_View, bool> selector, int maxDepth = 20)
        {
            var children = view.GetChildren().OfType <UIElement>();

            foreach (var sub in children)
            {
                if (selector(sub))
                {
                    yield return(sub);
                }
                else if (maxDepth > 0)
                {
                    var childGroup = sub as _ViewGroup;

                    if (childGroup != null)
                    {
                        foreach (var subResult in childGroup.EnumerateAllChildren(selector, maxDepth - 1))
                        {
                            yield return(subResult);
                        }
                    }
                }
            }
        }
示例#47
0
        public static void PopUIElement(
            Windows.UI.Xaml.UIElement element,
            double scaleWidthFrom,
            double scaleWidthTo,
            double scaleHeightFrom,
            double scaleHeightTo,
            double moveWidthFrom,
            double moveWidthTo,
            double moveHeightFrom,
            double moveHeightTo,
            EasingFunctionBase easingFunc)
        {
            // animation
            element.RenderTransform = new CompositeTransform();
            Storyboard      sb     = new Storyboard();
            DoubleAnimation scalex = new DoubleAnimation()
            {
                From           = scaleWidthFrom,
                To             = scaleWidthTo,
                Duration       = TimeSpan.FromSeconds(inAnimationDurationSec),
                EasingFunction = easingFunc
            };
            DoubleAnimation scaley = new DoubleAnimation()
            {
                From           = scaleHeightFrom,
                To             = scaleHeightTo,
                Duration       = TimeSpan.FromSeconds(inAnimationDurationSec),
                EasingFunction = easingFunc
            };
            DoubleAnimation movex = new DoubleAnimation()
            {
                // move from the center of the cell to its left
                From           = moveWidthFrom,
                To             = moveWidthTo,
                Duration       = TimeSpan.FromSeconds(inAnimationDurationSec),
                EasingFunction = easingFunc
            };
            DoubleAnimation movey = new DoubleAnimation()
            {
                // move from the center of the cell to its top
                From           = moveHeightFrom,
                To             = moveHeightTo,
                Duration       = TimeSpan.FromSeconds(inAnimationDurationSec),
                EasingFunction = easingFunc
            };

            sb.Children.Add(scalex);
            sb.Children.Add(scaley);
            Storyboard.SetTargetProperty(scalex, "(UIElement.RenderTransform).(ScaleTransform.ScaleX)");
            Storyboard.SetTargetProperty(scaley, "(UIElement.RenderTransform).(ScaleTransform.ScaleY)");
            Storyboard.SetTarget(scalex, element);
            Storyboard.SetTarget(scaley, element);

            sb.Children.Add(movex);
            sb.Children.Add(movey);
            Storyboard.SetTargetProperty(movex, "(UIElement.RenderTransform).(CompositeTransform.TranslateX)");
            Storyboard.SetTargetProperty(movey, "(UIElement.RenderTransform).(CompositeTransform.TranslateY)");
            Storyboard.SetTarget(movex, element);
            Storyboard.SetTarget(movey, element);

            sb.Begin();
        }
示例#48
0
 /// <summary>
 /// Applies the clip rectangle.
 /// </summary>
 /// <param name="image">The image.</param>
 /// <param name="x">The x offset of the element.</param>
 /// <param name="y">The y offset of the element.</param>
 private void ApplyClip(Windows.UI.Xaml.UIElement image, double x, double y)
 {
     image.Clip = new RectangleGeometry {
         Rect = new Rect(this.clipRect.X - x, this.clipRect.Y - y, this.clipRect.Width, this.clipRect.Height)
     };
 }
示例#49
0
 private void MyImageButton_ContextRequested(Windows.UI.Xaml.UIElement sender, ContextRequestedEventArgs args)
 {
     // always show a context menu in standard mode
     ShowMenu(false);
 }
        //Creates RenderTargetBitmap from UI Element

        public ScreenShotShare(Windows.UI.Xaml.UIElement s)
        {
            this.s = s;
            takeScreenShot();
        }
示例#51
0
 private void btn_LosingFocus(Windows.UI.Xaml.UIElement sender, Windows.UI.Xaml.Input.LosingFocusEventArgs args)
 {
     (sender as Button).Background = new SolidColorBrush(Colors.Gray);
 }
 private void ListBoxIndicators_GettingFocus(Windows.UI.Xaml.UIElement sender, Windows.UI.Xaml.Input.GettingFocusEventArgs args)
 {
 }
示例#53
0
        public static void ParentXaml(Windows.UI.Xaml.UIElement root)
        {
            var host = new WindowsXamlHost();

            host.Child = root;
        }
 /// <summary>
 /// DragStarting is called even if we are starting the Drag Operation ourselved with StartDragAsync
 /// In this sample, we don't really need to handle it
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void SourceTextBlock_DragStarting(Windows.UI.Xaml.UIElement sender, Windows.UI.Xaml.DragStartingEventArgs e)
 {
     e.Data.RequestedOperation = DataPackageOperation.Copy;
     e.Data.SetText(_symbol);
 }
示例#55
0
 public Point GetPosition(UIElement relativeTo)
 => _info.GetPosition(relativeTo);