public static Rect GetBoundingBox(FrameworkElement child, FrameworkElement parent) { GeneralTransform transform = child.TransformToAncestor(parent); Point topLeft = transform.Transform(new Point(0, 0)); Point bottomRight = transform.Transform(new Point(child.ActualWidth, child.ActualHeight)); return(new Rect(topLeft, bottomRight)); //return topLeft; }
/// <summary> /// Get the top and bottom of an element with respect to its parent. /// </summary> /// <param name="element">The element to get the position of.</param> /// <param name="parent">The parent of the element.</param> /// <param name="top">Vertical offset to the top of the element.</param> /// <param name="bottom"> /// Vertical offset to the bottom of the element. /// </param> public static void GetTopAndBottom(this FrameworkElement element, FrameworkElement parent, out double top, out double bottom) { Debug.Assert(element != null, "element should not be null!"); Debug.Assert(parent != null, "parent should not be null!"); GeneralTransform transform = element.TransformToVisual(parent); top = transform.Transform(new Point(0, 0)).Y; bottom = transform.Transform(new Point(0, element.ActualHeight)).Y; }
private Rect GetBoundingBox(FrameworkElement element, UserControl containerWindow) { GeneralTransform transform = element.TransformToAncestor(containerWindow); //To get the left and top location of the element. Point topLeft = transform.Transform(new Point(0, 0)); //To get the right and bottom point of the element using height and width. Point bottomRight = transform.Transform(new Point(element.ActualWidth, element.ActualHeight)); return(new Rect(topLeft, bottomRight)); }
/// <summary>Excludes a UI element from the Aero Glass frame.</summary> /// <param name="element">The element to exclude.</param> /// <param name="window">The window the element resides in.</param> /// <remarks> /// cMany non-WPF rendered controls (i.e., the ExplorerBrowser control) will not render properly on top of an /// Aero Glass frame. /// </remarks> public static void ExcludeElementFromAeroGlass(FrameworkElement element, Window window) { if (element == null) { throw new ArgumentNullException("element"); } if (window == null) { throw new ArgumentNullException("window"); } IntPtr handle = new WindowInteropHelper(window).Handle; if (!IsGlassEnabled) { return; } // calculate total size of window non-client area var handleSource = PresentationSource.FromVisual(window) as HwndSource; var windowRect = new Rect(); var clientRect = new Rect(); if (handleSource != null) { NativeMethods.GetWindowRect(handleSource.Handle, ref windowRect); NativeMethods.GetClientRect(handleSource.Handle, ref clientRect); } var nonClientSize = new Size( (windowRect.Right - windowRect.Left) - (double)(clientRect.Right - clientRect.Left), (windowRect.Bottom - windowRect.Top) - (double)(clientRect.Bottom - clientRect.Top)); // calculate size of element relative to non-client area GeneralTransform transform = element.TransformToAncestor(window); Point topLeftFrame = transform.Transform(new Point(0, 0)); Point bottomRightFrame = transform.Transform( new Point(element.ActualWidth + nonClientSize.Width, element.ActualHeight + nonClientSize.Height)); // Create a margin structure var margins = new Margins( (int)topLeftFrame.X, (int)topLeftFrame.Y, (int)(window.ActualWidth - bottomRightFrame.X), (int)(window.ActualHeight - bottomRightFrame.Y)); // Extend the Frame into client area if (NativeMethods.DwmExtendFrameIntoClientArea(handle, ref margins) != 0) { // throw new InvalidOperationException(); } }
public static Line TransformInt(GeneralTransform transform, Line line) { Point point1 = GeometryUtils.CreateIntPoint(line.X1, line.Y1); Point point2 = GeometryUtils.CreateIntPoint(line.X2, line.Y2); point1 = transform.Transform(point1); point2 = transform.Transform(point2); Line newLine = GeometryUtils.CreateLine(point1, point2); return(newLine); }
/// <summary> /// Indicate whether the specified item is currently visible. /// </summary> /// <param name="item">The item.</param> /// <param name="itemsHostRect">Rect for the item host element.</param> /// <param name="listBoxItemRect">Rect for the ListBoxItem element.</param> /// <returns>True if the item is visible; false otherwise.</returns> /// <remarks>Similar to WPF's corresponding ItemsControl method.</remarks> private bool IsOnCurrentPage(object item, out Rect itemsHostRect, out Rect listBoxItemRect) { // Get Rect for item host element DependencyObject ItemsHost = VisualTreeHelper.GetChild(this, 0); ItemsHost = VisualTreeHelper.GetChild(ItemsHost, 0); FrameworkElement itemsHost = (null != TemplateScrollViewer) ? ((null != TemplateScrollViewer.ElementScrollContentPresenter) ? TemplateScrollViewer.ElementScrollContentPresenter as FrameworkElement : TemplateScrollViewer as FrameworkElement) : ItemsHost as FrameworkElement; if (itemsHost == null) { itemsHostRect = Rect.Empty; listBoxItemRect = Rect.Empty; return(false); } itemsHostRect = new Rect(new Point(), new Point(itemsHost.RenderSize.Width, itemsHost.RenderSize.Height)); ListBoxItem listBoxItem = (ListBoxItem)ItemContainerGenerator.ContainerFromItem(item); if (listBoxItem == null) { listBoxItemRect = Rect.Empty; return(false); } listBoxItemRect = new Rect(new Point(), listBoxItem.RenderSize); // Adjust Rect to account for padding Control itemsHostControl = itemsHost as Control; if (null != itemsHostControl) { Thickness padding = itemsHostControl.Padding; itemsHostRect = new Rect( itemsHostRect.Left + padding.Left, itemsHostRect.Top + padding.Top, itemsHostRect.Width - padding.Left - padding.Right, itemsHostRect.Height - padding.Top - padding.Bottom); } // Get relative Rect for ListBoxItem GeneralTransform generalTransform = listBoxItem.TransformToVisual(itemsHost); if (generalTransform != null) { listBoxItemRect = new Rect(generalTransform.Transform(new Point()), generalTransform.Transform(new Point(listBoxItem.RenderSize.Width, listBoxItem.RenderSize.Height))); } // Return result return(IsVerticalOrientation() ? (itemsHostRect.Top <= listBoxItemRect.Top) && (listBoxItemRect.Bottom <= itemsHostRect.Bottom) : (itemsHostRect.Left <= listBoxItemRect.Left) && (listBoxItemRect.Right <= itemsHostRect.Right)); }
private static void OnDragCompleted(ManipulationDeltaEventArgs lastDragInfo, ManipulationCompletedEventArgs completedInfo = null) { GeneralTransform deltaTransform = null; Point releasePoint; Point totalTranslation; Point finalVelocity; Orientation orientation = Orientation.Horizontal; bool gestureCompleted = false; releasePoint = totalTranslation = finalVelocity = new Point(); if (completedInfo != null) { gestureCompleted = true; deltaTransform = GetInverseTransform(false, completedInfo.ManipulationContainer); totalTranslation = deltaTransform.Transform(completedInfo.TotalManipulation.Translation); finalVelocity = deltaTransform.Transform(completedInfo.FinalVelocities.LinearVelocity); if (completedInfo.IsInertial) { RaiseGestureEvent( (handler) => handler.Flick, () => new Microsoft.Phone.Controls.FlickGestureEventArgs( _gestureOrigin, finalVelocity), true); } } else { deltaTransform = GetInverseTransform(false, lastDragInfo.ManipulationContainer); totalTranslation = deltaTransform.Transform(lastDragInfo.CumulativeManipulation.Translation); finalVelocity = deltaTransform.Transform(lastDragInfo.Velocities.LinearVelocity); } releasePoint = new Point(_gestureOrigin.X + totalTranslation.X, _gestureOrigin.Y + totalTranslation.Y); orientation = GetOrientation(totalTranslation.X, totalTranslation.Y); RaiseGestureEvent( (handler) => handler.DragCompleted, () => new Microsoft.Phone.Controls.DragCompletedGestureEventArgs( _gestureOrigin, releasePoint, totalTranslation, orientation, finalVelocity), false); if (gestureCompleted) { OnGestureComplete(_gestureOrigin, releasePoint); } }
System.Windows.Point ApplyRotationInversion(double x, double y) { System.Windows.Point ret = new System.Windows.Point(x, y); if (IsRotated) { ret = rotationMatrixInvert.Transform(ret); } return(ret); }
/// <summary> /// Updates the render transform applied on the overlay. /// </summary> private void UpdateRenderTransform() { if (this._root != null && this.ContentRoot != null) { // The Overlay part should not be affected by the render transform applied on the // ChildWindow. In order to achieve this, we adjust an identity matrix to represent // the _root's transformation, invert it, apply the inverted matrix on the _root, so that // nothing is affected by the rendertransform, and apply the original transform only on the Content GeneralTransform gt = this._root.TransformToVisual(null); if (gt != null) { Point p10 = new Point(1, 0); Point p01 = new Point(0, 1); Point transform10 = gt.Transform(p10); Point transform01 = gt.Transform(p01); Matrix transformToRootMatrix = Matrix.Identity; transformToRootMatrix.M11 = transform10.X; transformToRootMatrix.M12 = transform10.Y; transformToRootMatrix.M21 = transform01.X; transformToRootMatrix.M22 = transform01.Y; MatrixTransform original = new MatrixTransform(); original.Matrix = transformToRootMatrix; InvertMatrix(ref transformToRootMatrix); MatrixTransform mt = new MatrixTransform(); mt.Matrix = transformToRootMatrix; TransformGroup tg = this._root.RenderTransform as TransformGroup; if (tg != null) { tg.Children.Add(mt); } else { this._root.RenderTransform = mt; } tg = this.ContentRoot.RenderTransform as TransformGroup; if (tg != null) { tg.Children.Add(original); } else { this.ContentRoot.RenderTransform = original; } } } }
private Point[] GetPointsFromSquare(FrameworkElement view) { UIElement parent = VisualTreeHelper.GetParent(view) as UIElement; GeneralTransform transform = view.TransformToAncestor(parent); Point topLeft = transform.Transform(new Point(0, 0)); Point topRight = transform.Transform(new Point(view.ActualWidth, 0)); Point bottomRight = transform.Transform(new Point(view.ActualWidth, View.ActualHeight)); Point bottomLeft = transform.Transform(new Point(0, view.ActualHeight)); return(new Point[] { topLeft, topRight, bottomRight, bottomLeft }); }
/// <summary> /// Executed when mouse moves on the chrome. /// </summary> /// <param name="sender">Sender object.</param> /// <param name="e">Mouse event args.</param> private void Chrome_MouseMove(object sender, MouseEventArgs e) { if (this._isMouseCaptured && this.ContentRoot != null) { // If the child window is dragged out of the page, return if (System.Windows.Application.Current != null && System.Windows.Application.Current.RootVisual != null && (e.GetPosition(System.Windows.Application.Current.RootVisual).X < 0 || e.GetPosition(System.Windows.Application.Current.RootVisual).Y < 0)) { return; } Point position = e.GetPosition(System.Windows.Application.Current.RootVisual); GeneralTransform transform = this.ContentRoot.TransformToVisual(System.Windows.Application.Current.RootVisual); if (transform != null) { Point point2 = transform.Transform(this._clickPoint); this._windowPosition = transform.Transform(new Point(0.0, 0.0)); if (position.X < 0.0) { double num = FindPositionY(point2, position, 0.0); position = new Point(0.0, num); } if (position.X > base.Width) { double num2 = FindPositionY(point2, position, base.Width); position = new Point(base.Width, num2); } if (position.Y < 0.0) { double num3 = FindPositionX(point2, position, 0.0); position = new Point(num3, 0.0); } if (position.Y > base.Height) { double num4 = FindPositionX(point2, position, base.Height); position = new Point(num4, base.Height); } double x = position.X - point2.X; double y = position.Y - point2.Y; FrameworkElement rootVisual = System.Windows.Application.Current.RootVisual as FrameworkElement; if ((rootVisual != null) && (rootVisual.FlowDirection == FlowDirection.RightToLeft)) { x = -x; } this.UpdateContentRootTransform(x, y); } if (Moving != null) { Moving(this, e); } } }
public void UpdateBounds() { if (this.IsVisible) { GeneralTransform gt = this.game.TransformToVisual(this.TopLevelWindow); this.Width = this._frontWindow.Width = this.game.ActualWidth; this.Height = this._frontWindow.Height = this.game.ActualHeight; this.Left = this._frontWindow.Left = this.TopLevelWindow.Left + gt.Transform(new Point(0, 0)).X + 8; this.Top = this._frontWindow.Top = this.TopLevelWindow.Top + gt.Transform(new Point(0, 0)).Y + 28; } }
internal static Matrix CreateMatrix(GeneralTransform transform) { if (transform != null && !IsIdentity(transform)) { Point offset = transform.Transform(new Point(0, 0)); Point i = transform.Transform(new Point(1, 0)).Minus(offset); Point j = transform.Transform(new Point(0, 1)).Minus(offset); Matrix matrix = new Matrix(i.X, i.Y, j.X, j.Y, offset.X, offset.Y); return(matrix); } else { return(Matrix.Identity); } }
/// <summary> /// Function to deal with mouse capture when off the mesh. /// </summary> /// <param name="imv3DHit">The model hit</param> /// <param name="mousePos">The location of the mouse</param> private void HandleMouseCaptureButOffMesh(InteractiveVisual3D imv3DHit, Point mousePos) { // process the mouse capture if it exists UIElement uie = (UIElement)Mouse.Captured; // get the size of the element Rect contBounds = VisualTreeHelper.GetDescendantBounds(uie); // translate to the parent's coordinate system GeneralTransform gt = uie.TransformToAncestor(_hiddenVisual); Point[] visCorners = new Point[4]; // get the points relative to the parent visCorners[0] = gt.Transform(new Point(contBounds.Left, contBounds.Top)); visCorners[1] = gt.Transform(new Point(contBounds.Right, contBounds.Top)); visCorners[2] = gt.Transform(new Point(contBounds.Right, contBounds.Bottom)); visCorners[3] = gt.Transform(new Point(contBounds.Left, contBounds.Bottom)); // get the u,v texture coordinate values of the above points Point[] texCoordsOfInterest = new Point[4]; for (int i = 0; i < visCorners.Length; i++) { texCoordsOfInterest[i] = VisualCoordsToTextureCoords(visCorners[i], _hiddenVisual); } // get the edges that map to the given visual List <HitTestEdge> edges = imv3DHit.GetVisualEdges(texCoordsOfInterest); if (Debug) { AdornerLayer myAdornerLayer = AdornerLayer.GetAdornerLayer(this); if (_DEBUGadorner == null) { _DEBUGadorner = new DebugEdgesAdorner(this, edges); myAdornerLayer.Add(_DEBUGadorner); } else { myAdornerLayer.Remove(_DEBUGadorner); _DEBUGadorner = new DebugEdgesAdorner(this, edges); myAdornerLayer.Add(_DEBUGadorner); } } // find the closest intersection of the mouse position and the edge list FindClosestIntersection(mousePos, edges, imv3DHit); }
void MoveImeCompositionWindow() { if (imeState.Context == IntPtr.Zero) { return; } var line = ContainingTextViewLine; if (line.VisibilityState == VisibilityState.Unattached) { return; } var charBounds = line.GetExtendedCharacterBounds(currentPosition); const int CFS_DEFAULT = 0x0000; const int CFS_FORCE_POSITION = 0x0020; var compForm = new ImeState.COMPOSITIONFORM(); compForm.dwStyle = CFS_DEFAULT; var rootVisual = imeState.HwndSource.RootVisual; GeneralTransform generalTransform = null; if (rootVisual != null && rootVisual.IsAncestorOf(textView.VisualElement)) { generalTransform = textView.VisualElement.TransformToAncestor(rootVisual); } var compTarget = imeState.HwndSource.CompositionTarget; if (generalTransform != null && compTarget != null) { var transform = compTarget.TransformToDevice; compForm.dwStyle = CFS_FORCE_POSITION; var caretPoint = transform.Transform(generalTransform.Transform(new Point(charBounds.Left - textView.ViewportLeft, charBounds.TextTop - textView.ViewportTop))); var viewPointTop = transform.Transform(generalTransform.Transform(new Point(0, 0))); var viewPointBottom = transform.Transform(generalTransform.Transform(new Point(textView.ViewportWidth, textView.ViewportHeight))); compForm.ptCurrentPos = new ImeState.POINT(Math.Max(0, (int)caretPoint.X), Math.Max(0, (int)caretPoint.Y)); compForm.rcArea = new ImeState.RECT( Math.Max(0, (int)viewPointTop.X), Math.Max(0, (int)viewPointTop.Y), Math.Max(0, (int)viewPointBottom.X), Math.Max(0, (int)viewPointBottom.Y)); } ImeState.ImmSetCompositionWindow(imeState.Context, ref compForm); }
public void QueueMouseMove(Point mousePos, GeneralTransform screenToSceneTransform) { mousePos = screenToSceneTransform.Transform(mousePos); Rect minimumBounds = screenToSceneTransform.TransformBounds(_minimumDistance); _mousePosQueue.Add(new PointAndBounds(mousePos, minimumBounds)); }
/// <summary> /// Handles when the mouse moves /// </summary> /// <param name="mousePos"></param> /// <param name="screenToSceneTransform"></param> public void MouseMoved(Point mousePos, GeneralTransform screenToSceneTransform) { if (screenToSceneTransform == null) { return; } // Convert the mouse coordinates to scene coordinates mousePos = screenToSceneTransform.Transform(mousePos); bool newLocked = false; Point newPoint = mousePos; if (points.Count > 0) { // Transform the minimum distance ignoring the translation Rect minimumBounds = screenToSceneTransform.TransformBounds(minimumDistance); double nearestDistanceSquared; newPoint = GetEllipseScaledNearestPoint(points, mousePos, (Vector)(minimumBounds.Size), out nearestDistanceSquared); newLocked = nearestDistanceSquared <= 1; } bool lockedChanged = newLocked != locked; bool pointChanged = newPoint != closestPoint; locked = newLocked; closestPoint = newPoint; if ((pointChanged && locked) || lockedChanged) { OnClosestPointChanged(); } }
public void ZoomToObject(FrameworkElement targetObject, bool isAnimated) { if (!isAnimated) { GeneralTransform gt = targetObject.TransformToAncestor(_rootElement); Point point = gt.Transform(new Point()); Size size = new Size(targetObject.ActualWidth, targetObject.ActualHeight); double zoomX = _rootElement.ActualWidth / size.Width; double zoomY = _rootElement.ActualHeight / size.Height; double zoomFactor = Math.Min(zoomX, zoomY); Thickness margin = new Thickness(); double diffScreenY = (_rootElement.ActualHeight - zoomFactor * size.Height); double diffScreenX = (_rootElement.ActualWidth - zoomFactor * size.Width); margin.Top = -((point.Y * zoomFactor) - ((diffScreenY / 2))); margin.Left = -((point.X * zoomFactor) - ((diffScreenX / 2))); ZoomFactor = zoomFactor; _rootElement.Margin = margin; _rootElement.UpdateLayout(); } else { ZoomToObjectAnimated(targetObject); } }
private void MyMap_MouseClick(object sender, ESRI.ArcGIS.Client.Map.MouseEventArgs e) { CsvLayer csvLayer = MyMap.Layers["MyCSVLayer"] as CsvLayer; System.Windows.Point screenPnt = MyMap.MapToScreen(e.MapPoint); // Account for difference between Map and application origin GeneralTransform generalTransform = MyMap.TransformToVisual(null); System.Windows.Point transformScreenPnt = generalTransform.Transform(screenPnt); int tolerance = 20; Rect screenRect = new Rect(new Point(transformScreenPnt.X - tolerance / 2, transformScreenPnt.Y - tolerance / 2), new Point(transformScreenPnt.X + tolerance / 2, transformScreenPnt.Y + tolerance / 2)); IEnumerable <Graphic> selected = csvLayer.FindGraphicsInHostCoordinates(screenRect); foreach (Graphic g in selected) { MyInfoWindow.Anchor = e.MapPoint; MyInfoWindow.IsOpen = true; //Since a ContentTemplate is defined, Content will define the DataContext for the ContentTemplate MyInfoWindow.Content = g.Attributes; return; } }
public void HandleMouseMove(Point movePoint) { if (this.ItemImage.Value == null) { return; } GeneralTransform selectToPixel = GeometryUtils.CreateTransform(this.itemTransform.pixelToSelect.Inverse); Point pixelPoint = selectToPixel.Transform(movePoint); if (this.updatePositionLabelStopWatch.ElapsedMilliseconds > this.updatePositionLabelMsDelay) { UpdatePositionLabel(pixelPoint); } if (this.updateSelectLineStopWatch.ElapsedMilliseconds > this.updateSelectLineMsDelay && this.isMouseDown && !this.IsSelectingTransparency.Value) { DrawSelectLinesFromPixels(this.lastSelectPoint, pixelPoint); } else if (this.updateTransparentColorStopWatch.ElapsedMilliseconds > this.updateTransparentColorMsDelay && this.isMouseDown && this.IsSelectingTransparency.Value) { this.TilesetModel.Value.TransparentColor.Value = ImageUtils.ColorAt(this.ItemImage.Value, pixelPoint); } }
private void UpdatePositionLabel(Point position) { Point transformedPosition = new Point(0, 0); if (this.TileImage != null) { switch (this.Scale.Value) { case ScaleType.Pixel: transformedPosition = position; break; case ScaleType.Tile: GeneralTransform transform = GeometryUtils.CreateTransform(this.itemTransform.pixelToTile); transformedPosition = transform.Transform(position); break; } } transformedPosition = GeometryUtils.CreateIntPoint(transformedPosition); Application.Current.Dispatcher.BeginInvoke(new Action(() => { this.PositionText.Value = (transformedPosition.X + ", " + transformedPosition.Y); }), DispatcherPriority.Render); updatePositionLabelStopWatch.Restart(); }
/// <summary> /// Keeps the background VisualBrush synced up with the passed in Visual, utilizing the Viewbox to do so, /// as the attached object could be moving around on top of the passed in Visual. /// </summary> private void EnsureBrushSyncWithVisual() { if (m_attachedObject == null || Visual == null) { return; } // Make the background visual the same size of our attached FrameworkElement. m_backgroundVisual.Width = m_attachedObject.ActualWidth; m_backgroundVisual.Height = m_attachedObject.ActualHeight; // Get the transform of our attached FrameworkElement to the Visual we want to use as our background. GeneralTransform trans = m_attachedObject.TransformToVisual(Visual); // Calculate the difference between 0,0 coord of our attached FrameworkElement // and 0,0 coord of our target Visual for the background. Point pos = trans.Transform(new Point(0, 0)); // Create a new Viewbox for the VisualBrush. This shows a specific area of the Visual. var viewbox = new Rect { X = pos.X, Y = pos.Y, Width = m_attachedObject.ActualWidth, Height = m_attachedObject.ActualHeight }; m_backgroundVisualBrush.Viewbox = viewbox; }
public void Show(UIElement relativeTo, double offsetX, double offsetY) { #if SILVERLIGHT try { GeneralTransform gt = relativeTo.TransformToVisual((UIElement)this.Parent); Point offset = gt.Transform(new Point(offsetX, offsetY)); ItemPopup.VerticalOffset = offset.Y; ItemPopup.HorizontalOffset = offset.X; ItemPopup.IsOpen = true; ItemGrid.Measure(App.Current.RootVisual.DesiredSize); GeneralTransform transform = relativeTo.TransformToVisual(App.Current.RootVisual); double distBetweenBottomOfPopupAndBottomOfWindow = App.Current.RootVisual.RenderSize.Height - offsetY - transform.Transform(new Point(0, ItemGrid.DesiredSize.Height)).Y; if (distBetweenBottomOfPopupAndBottomOfWindow < 0) { ItemPopup.VerticalOffset += distBetweenBottomOfPopupAndBottomOfWindow; } } catch (ArgumentException) { // Value does not fall within the expected range // apparently happens if you call while it's still loading the visual tree or something } #else ItemPopup.PlacementTarget = relativeTo; ItemPopup.PlacementRectangle = new Rect(0, offsetY, offsetX, relativeTo.RenderSize.Height); ItemPopup.Placement = System.Windows.Controls.Primitives.PlacementMode.Right; ItemPopup.IsOpen = true; #endif }
public static bool CheckSize(StackPanel spBig, StackPanel spSpecial, double width, double height, Image qRImage) { if (qRImage != null && spSpecial != null) { GeneralTransform generalTransform = qRImage.TransformToVisual(Application.Current.MainWindow as UIElement); Point point = generalTransform.Transform(new Point(0, 0)); Rect qRImagerect = new Rect(point, new Size(qRImage.ActualWidth, qRImage.ActualHeight)); // LogHelper.Log("qRImage相对于屏幕原点的位置:" + qRImagerect.ToString()); Cul(spSpecial, qRImagerect); } spBig.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); if (spBig.DesiredSize.Width > width) { spBig.Background = Brushes.IndianRed; string x = " Need more " + ((spBig.RenderSize.Width - width) / (3.8) + 0.5) + "mm"; UIMainUtils.Error_("Width Too lang!!! Design:" + width + " Now:" + spBig.RenderSize.Width + x); return false; } if (spBig.DesiredSize.Height > height) { spBig.Background = Brushes.IndianRed; string x = " Need more " + ((spBig.RenderSize.Height - height) / (3.8) + 0.5) + "mm"; UIMainUtils.Error_("Height Too lang!!! Design:" + height + " Now:" + spBig.RenderSize.Height + x); return false; } return true; }
private void ZoomToObjectAnimated(FrameworkElement targetObject) { if (_rootElement != null) { double objectsActualCurrentZoom = 1; if (targetObject.LayoutTransform is ScaleTransform) { objectsActualCurrentZoom = (targetObject.LayoutTransform as ScaleTransform).ScaleX; if (targetObject is INestedZoomableControl) { objectsActualCurrentZoom = 1 / Math.Pow(GetScaleFactor(targetObject), (targetObject as INestedZoomableControl).NestedLevel); } } GeneralTransform gt = targetObject.TransformToAncestor(_rootElement); Point point = gt.Transform(new Point()); Size size = new Size(targetObject.ActualWidth * objectsActualCurrentZoom, targetObject.ActualHeight * objectsActualCurrentZoom); double zoomX = _rootElement.ActualWidth / size.Width; double zoomY = _rootElement.ActualHeight / size.Height; double zoomFactor = Math.Min(zoomX, zoomY); Thickness margin = new Thickness(); double diffScreenY = (_rootElement.ActualHeight - zoomFactor * size.Height); double diffScreenX = (_rootElement.ActualWidth - zoomFactor * size.Width); margin.Top = -((point.Y * zoomFactor) - ((diffScreenY / 2))); margin.Left = -((point.X * zoomFactor) - ((diffScreenX / 2))); _animZoom.From = ZoomFactor; _animZoom.To = zoomFactor; _animMargin.To = margin; _animMargin.From = _rootElement.Margin; _animPositionX.To = margin.Left; _animPositionX.From = PositionX; _animPositionY.To = margin.Top; _animPositionY.From = PositionY; OnZoomStarted(); this.BeginAnimation(ZoomFactorProperty, _animZoom); _rootElement.BeginAnimation(FrameworkElement.MarginProperty, _animMargin); if (targetObject is INotifyZoomChanged) { (targetObject as INotifyZoomChanged).OnZoomStarted(); DispatcherTimer timer = new DispatcherTimer(); timer.Interval = AnimationDuration.TimeSpan; timer.Tick += (s, e) => { (targetObject as INotifyZoomChanged).OnZoomCompleted(); OnZoomCompleted(); timer.Stop(); }; timer.Start(); } } }
/// <summary> /// Occurs when the the Sort By toggle button is clicked - shows the sortby popup menu /// </summary> private void SortByToggleButton_Click(object sender, RoutedEventArgs e) { if (SortByMenuPopup.IsOpen) { SortByMenuPopup.IsOpen = false; } else { // calculate the location of the popup and open it ToggleButton toggleButton = sender as ToggleButton; GeneralTransform gt = toggleButton.TransformToVisual(this); Point offset = gt.Transform(new Point(0, 0)); SortByMenuPopup.VerticalOffset = offset.Y + toggleButton.ActualHeight; SortByMenuBorder.Opacity = 0.01; SortByMenuPopup.IsOpen = true; // give the first toggle button focus so the SortByToggleButtonStackPanel can lose focus ((ToggleButton)SortByToggleButtonStackPanel.Children[0]).Focus(); Dispatcher.BeginInvoke(() => { SortByMenuPopup.HorizontalOffset = offset.X - SortByMenuBorder.ActualWidth + toggleButton.ActualWidth; SortByMenuBorder.Opacity = 1; }); } }
private void MyDrawObject_DrawComplete(object sender, DrawEventArgs args) { ESRI.ArcGIS.Client.Geometry.MapPoint point = args.Geometry as ESRI.ArcGIS.Client.Geometry.MapPoint; point.SpatialReference = MyMap.SpatialReference; System.Windows.Point screenPnt = MyMap.MapToScreen(point); // Account for difference between Map and application origin GeneralTransform generalTransform = MyMap.TransformToVisual(Application.Current.MainWindow); System.Windows.Point transformScreenPnt = generalTransform.Transform(screenPnt); IEnumerable <Graphic> selected = parcelGraphicsLayer.FindGraphicsInHostCoordinates(transformScreenPnt); foreach (Graphic g in selected) { if (g.Selected) { g.UnSelect(); selectedGraphics.Remove(g); } else { g.Select(); selectedGraphics.Add(g); } } if (selectedGraphics.Count > 1) { UnionButton.IsEnabled = true; } else { UnionButton.IsEnabled = false; } }
/// <summary> /// Gets the relative position of screenpoint to the working object. /// </summary> /// <param name="screenPoint">Point in screen space.</param> /// <returns>Point in relative object space.</returns> protected PointF getRelativePos(PointF screenPoint) { GeneralTransform gt = TopContainer.TransformToVisual(this.WorkingObject); System.Windows.Point curPoint = gt.Transform(new System.Windows.Point(screenPoint.X, screenPoint.Y)); return(new PointF((float)curPoint.X, (float)curPoint.Y)); }
/// <summary> /// 滚动至指定Item /// </summary> /// <param name="selection"></param> private void ScrollToSelection(object selection) { if (this.mScrollViewer == null) { return; } for (int i = 0; i < this.mHeaderList.Count; i++) { if (this.mHeaderList[i] == selection) { //获取子项相对于控件的位置 GeneralTransform generalTransform1 = this.mHeaderList[i].TransformToAncestor(this.PART_ContentPresenter); Point currentPoint = generalTransform1.Transform(new Point(0, 0)); double offsetY = this.mScrollViewer.VerticalOffset + currentPoint.Y; this.mScrollViewer.ScrollToVerticalOffset(offsetY); //DoubleAnimation doubleAnimation = new DoubleAnimation(this.oldOffsetY, offsetY, new Duration(TimeSpan.FromMilliseconds(500))); //this.mScrollViewer.BeginAnimation(ZScrollViewer.VerticalOffsetExProperty, doubleAnimation); //this.oldOffsetY = offsetY; //this.IndicatorSelectedIndex = i; break; } } }
void CheckHitBlock(object sender, MouseButtonEventArgs e, bool needPopBlock = true) { Canvas gameCanvas = UIHelper.FindVisualParent <Canvas>(sender as DependencyObject); //InitializeGame(); Point mousepos = e.GetPosition(gameCanvas); HitTestResult result = VisualTreeHelper.HitTest(gameCanvas, mousepos); GeneralTransform generalTransform1 = ((UIElement)(result.VisualHit)).TransformToAncestor(gameCanvas); Point currentPoint = generalTransform1.Transform(new Point(0, 0)); double left = currentPoint.X; double top = currentPoint.Y; uint row; uint col; LocateBlock(top, left, out row, out col); if (needPopBlock) { PopBlock(row, col); } else { SingleBlock item = FindBlock(row, col); MessageBox.Show("R" + item.Rowpos.ToString() + " C" + item.Columnpos.ToString() + " " + item.IsSelected.ToString() + " Color" + ((int)(item.BlockColor)).ToString()); } }