private static void FocusCore(FrameworkElement element)
		{
			//System.Diagnostics.Debug.WriteLine("Focusing element " + element.ToString());
			//System.Diagnostics.Debug.WriteLine(Environment.StackTrace);
			if (!element.Focus())
			{
				//System.Diagnostics.Debug.WriteLine("- Element could not be focused, invoking in dispatcher thread");
				element.Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() => element.Focus()));
			}

#if DEBUG
			// no good idea, seems to block sometimes
			int i = 0;
			while (i < 5)
			{
				if (element.IsFocused)
				{
					//if (i > 0)
					//    System.Diagnostics.Debug.WriteLine("- Element is focused now in round " + i + ", leaving");
					return;
				}
				Thread.Sleep(20);
				i++;
			}
			//if (i >= 5)
			//{
			//    System.Diagnostics.Debug.WriteLine("- Element is not focused after 500 ms, giving up");
			//}
#endif
		}
		public static void UpdateImageSource(FrameworkElement content, Grid hostBody, ImageSource imageSource, Stretch stretch)
		{
			if (hostBody == null || content == null)
				return;

			var imgRects = hostBody.Children.OfType<Rectangle>().ToArray();

			for (int i = imgRects.Count() - 1; i >= 0; i--)
			{
				hostBody.Children.Remove(imgRects[i]);
			}

			if (imageSource == null)
				return;

			var imgBrush = new ImageBrush { ImageSource = imageSource, Stretch = stretch };
			var imgRect = new Rectangle
			{
				OpacityMask = imgBrush
			};

			hostBody.Children.Add(imgRect);

			ApplyForegroundToFillBinding(content, imgRect);

			//var sb = new Storyboard();
			//ControlHelper.CreateDoubleAnimations(sb, imgBrush, "Opacity", 0.2, 1, 75);
			//hostBody.Dispatcher.BeginInvoke(sb.Begin);
		}
Exemplo n.º 3
0
 protected override void ValidateTemplatedParent(FrameworkElement templatedParent)
 {
     if (templatedParent == null)
         throw new ArgumentNullException("templatedParent");
     if (_TargetType != null && !_TargetType.IsInstanceOfType(templatedParent))
         throw new ArgumentException("Template target type mismatch.");
 }
 /// <summary>
 /// Remove the ViewModel from the View's DataContext
 /// </summary>
 /// <param name="frameworkElement"></param>
 /// <param name="viewModel"></param>
 public void UnbindViewModelFromView(FrameworkElement frameworkElement, object viewModel)
 {
     if (frameworkElement.DataContext == viewModel)
     {
         frameworkElement.DataContext = null;
     }
 }
 private static void CheckArgument(FrameworkElement element)
 {
     if (element == null)
     {
         throw new ArgumentNullException("element");
     }
 }
			public Helper(FrameworkElement obj, DependencyProperty property, Action<object, object> changed, object currentValue)
			{
				this.obj = obj;
				this.property = property; 
				this.changed = changed;
				this.currentValue = currentValue;
			}
Exemplo n.º 7
0
        public override IEnumerable<Timeline> CreateAnimation(FrameworkElement element)
        {
            double startRotation = 0.0;
            double endRotation;

            if (StartRotation.HasValue)
                startRotation = StartRotation.Value;
            else
            {
                var compositeTransform = element.RenderTransform as CompositeTransform;
                if (compositeTransform != null)
                    startRotation = compositeTransform.Rotation;
            }
            if (EndRotation.HasValue)
                endRotation = EndRotation.Value;
            else
                endRotation = startRotation + 360.0;

            return new Timeline[]
            {
                element.AnimatePointProperty(AnimationProperty.RenderTransformOrigin)
                    .AddDiscreteKeyFrame(0.0, new Point(0.5, 0.5)),

                element.AnimateProperty(AnimationProperty.Rotation)
                    .AddEasingKeyFrame(0.0, startRotation)
                    .AddEasingKeyFrame(Duration, endRotation, Easing)
                    .AddDiscreteKeyFrame(Duration, startRotation),
            };
        }
Exemplo n.º 8
0
		internal static void AddError (FrameworkElement element, ValidationError error)
		{
			var errors = GetErrorsCore (element);
			errors.Add (error);
			if (errors.Count == 1)
				SetHasError (element, true);
		}
        /*!
         * Initializes this calibration element
         * @param   rotationElement the element that rotates (can have children that travel with it)
         * @param   element the element that is touched to begin rotation, will track the finger
         * @param   the outer ring image
         * @param   the middle ring image
         * @param   the inner ring image
         * @param   sphero the sphero that will be calibrated
         */
        public CalibrateElement(
            FrameworkElement rotationElement,
            FrameworkElement element,
            FrameworkElement ringOuter,
            FrameworkElement ringMiddle,
            FrameworkElement ringInner,
            FrameworkElement fingerPoint,
            RobotKit.Robot sphero) {
            m_sphero = (RobotKit.Sphero)sphero;
            m_calibrateRotationRoot = rotationElement;
            m_calibrateElement = element;

            m_calibrateElement.PointerPressed += OnPointerPressed;
            m_calibrateElement.PointerMoved += OnPointerMoved;
            m_calibrateElement.PointerReleased += OnPointerReleased;
            m_calibrateElement.PointerCaptureLost += OnPointerReleased;
            m_calibrateElement.PointerCanceled += OnPointerReleased;

            m_ringOuter = ringOuter;
            m_ringMiddle = ringMiddle;
            m_ringInner = ringInner;

            m_fingerPoint = fingerPoint;

            SetupRotation();

            m_lastCommandSentTimeMs = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
        }
Exemplo n.º 10
0
        /// <summary>Initializes the view model and registers events so that the OnLoaded and OnUnloaded methods are called. 
        /// This method must be called in the constructor after the <see cref="InitializeComponent"/> method call. </summary>
        /// <param name="viewModel">The view model. </param>
        /// <param name="view">The view. </param>
        public static void RegisterViewModel(ViewModelBase viewModel, FrameworkElement view)
        {
            viewModel.Initialize();

            view.Loaded += (sender, args) => viewModel.CallOnLoaded();
            view.Unloaded += (sender, args) => viewModel.CallOnUnloaded();
        }
Exemplo n.º 11
0
        /// <summary>
        /// Called when template should be applied to the control
        /// </summary>
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            _elementHorizontalTemplateFrameworkElement = this.GetTemplateChild(PreviewControl.ElementHorizontalTemplateName) as FrameworkElement;
            _elementVerticalTemplateFrameworkElement = this.GetTemplateChild(PreviewControl.ElementVerticalTemplateName) as FrameworkElement;

            if (_currentGridResizeDirection == GridSplitter.GridResizeDirection.Columns)
            {
                if (_elementHorizontalTemplateFrameworkElement != null)
                {
                    _elementHorizontalTemplateFrameworkElement.Visibility = Visibility.Collapsed;
                }
                if (_elementVerticalTemplateFrameworkElement != null)
                {
                    _elementVerticalTemplateFrameworkElement.Visibility = Visibility.Visible;
                }
            }
            else
            {
                if (_elementHorizontalTemplateFrameworkElement != null)
                {
                    _elementHorizontalTemplateFrameworkElement.Visibility = Visibility.Visible;
                }
                if (_elementVerticalTemplateFrameworkElement != null)
                {
                    _elementVerticalTemplateFrameworkElement.Visibility = Visibility.Collapsed;
                }
            }
        }
Exemplo n.º 12
0
 public DataGridCellEditingCancelEventArgs(DataGridColumnBase dataGridColumn, 
                                           DataGridRow dataGridRow,
                                           FrameworkElement element,
                                           DataGridEditingTriggerInfo editingTriggerInfo) : base(dataGridColumn, dataGridRow, element) 
 {
     this.EditingTriggerInfo = editingTriggerInfo;
 } 
Exemplo n.º 13
0
 public override IEnumerable<Timeline> CreateAnimation(FrameworkElement element)
 {
     return new Timeline[]
     {
         element.AnimateProperty(AnimationProperty.Opacity)
             .AddDiscreteKeyFrame(0.0, 1),
         element.AnimateProperty(AnimationProperty.Rotation)
             .AddDiscreteKeyFrame(0.0, 0),
         element.AnimateProperty(AnimationProperty.TranslateX)
             .AddDiscreteKeyFrame(0.0, 0),
         element.AnimateProperty(AnimationProperty.TranslateY)
             .AddDiscreteKeyFrame(0.0, 0),
         element.AnimateProperty(AnimationProperty.ScaleX)
             .AddDiscreteKeyFrame(0.0, 1),
         element.AnimateProperty(AnimationProperty.ScaleY)
             .AddDiscreteKeyFrame(0.0, 1),
         element.AnimateProperty(AnimationProperty.RotationX)
             .AddDiscreteKeyFrame(0.0, 0),
         element.AnimateProperty(AnimationProperty.RotationY)
             .AddDiscreteKeyFrame(0.0, 0),
         element.AnimateProperty(AnimationProperty.RotationZ)
             .AddDiscreteKeyFrame(0.0, 0),
         element.AnimatePointProperty(AnimationProperty.RenderTransformOrigin)
             .AddDiscreteKeyFrame(0.0, new Point(0.5, 0.5)),
     };
 }
Exemplo n.º 14
0
        public override IEnumerable<Timeline> CreateAnimation(FrameworkElement element)
        {
            var transform = GetTransform(element);

            var animations = new List<Timeline>();
            if (Math.Abs(DistanceY) > 0.001)
                animations.Add(
                    element.AnimateProperty(AnimationProperty.TranslateY)
                        .AddEasingKeyFrame(0.0, transform.TranslateY)
                        .AddEasingKeyFrame(Duration * 0.2, transform.TranslateY)
                        .AddEasingKeyFrame(Duration * 0.4, transform.TranslateY + DistanceY)
                        .AddEasingKeyFrame(Duration * 0.5, transform.TranslateY)
                        .AddEasingKeyFrame(Duration * 0.6, transform.TranslateY + (DistanceY / 2))
                        .AddEasingKeyFrame(Duration * 0.8, transform.TranslateY)
                        .AddEasingKeyFrame(Duration, transform.TranslateY)
                    );
            if (Math.Abs(DistanceX) > 0.001)
                animations.Add(
                    element.AnimateProperty(AnimationProperty.TranslateX)
                        .AddEasingKeyFrame(0.0, transform.TranslateX)
                        .AddEasingKeyFrame(Duration * 0.2, transform.TranslateX)
                        .AddEasingKeyFrame(Duration * 0.4, transform.TranslateX + DistanceX)
                        .AddEasingKeyFrame(Duration * 0.5, transform.TranslateX)
                        .AddEasingKeyFrame(Duration * 0.6, transform.TranslateX + (DistanceX / 2))
                        .AddEasingKeyFrame(Duration * 0.8, transform.TranslateX)
                        .AddEasingKeyFrame(Duration, transform.TranslateX)
                    );
            return animations;
        }
Exemplo n.º 15
0
 public void Resume(FrameworkElement target)
 {
     if (Storyboard != null)
     {
         Storyboard.Pause(target);
     }
 }
Exemplo n.º 16
0
 public void Remove(FrameworkElement target, INameScope nameScope, object layerOwner)
 {
     if (Storyboard != null)
     {
         Storyboard.Remove(target, nameScope, layerOwner);
     }
 }
Exemplo n.º 17
0
 public void SkipToFill(FrameworkElement target)
 {
     if (Storyboard != null)
     {
         Storyboard.SkipToFill(target);
     }
 }
Exemplo n.º 18
0
        public override IEnumerable<Timeline> CreateAnimation(FrameworkElement element)
        {
            var transform = GetTransform(element);

            return new Timeline[]
            {
                element.AnimatePointProperty(AnimationProperty.RenderTransformOrigin)
                    .AddDiscreteKeyFrame(0.0, new Point(0, 1)),

                element.AnimateProperty(AnimationProperty.Opacity)
                    .AddEasingKeyFrame(0.0, 0)
                    .AddEasingKeyFrame(Duration*0.6, 1),

                element.AnimateProperty(AnimationProperty.TranslateX)
                    .AddEasingKeyFrame(0.0, transform.TranslateX + 700)
                    .AddEasingKeyFrame(Duration*0.6, transform.TranslateX - 30, new QuadraticEase())
                    .AddEasingKeyFrame(Duration*0.8, transform.TranslateX),

                element.AnimateProperty(AnimationProperty.SkewX)
                    .AddEasingKeyFrame(0.0, -30)
                    .AddEasingKeyFrame(Duration*0.6, 30)
                    .AddEasingKeyFrame(Duration*0.8, -15)
                    .AddEasingKeyFrame(Duration, 0),
            };
        }
Exemplo n.º 19
0
    public virtual void SetupEffect(FrameworkElement parent, ref PositionColoredTextured[] verts, float zOrder, bool adaptVertsToBrushTexture)
    {
      if (!UpdateBounds(ref verts))
        return;
      float w = _vertsBounds.Width;
      float h = _vertsBounds.Height;
      float xoff = _vertsBounds.X;
      float yoff = _vertsBounds.Y;
      if (adaptVertsToBrushTexture)
        for (int i = 0; i < verts.Length; i++)
        {
          PositionColoredTextured vert = verts[i];
          float x = vert.X;
          float u = x - xoff;
          u /= w;

          float y = vert.Y;
          float v = y - yoff;
          v /= h;

          if (u < 0) u = 0;
          if (u > 1) u = 1;
          if (v < 0) v = 0;
          if (v > 1) v = 1;
          unchecked
          {
            Color4 color = ColorConverter.FromColor(Color.White);
            vert.Color = color.ToBgra();
          }
          vert.Tu1 = u;
          vert.Tv1 = v;
          vert.Z = zOrder;
          verts[i] = vert;
        }
    }
 /// <summary>
 /// if the view model implements the IParentDataContextAwareViewModel interface then the parents view will be disconnected.
 /// </summary>
 /// <param name="frameworkElement"></param>
 /// <param name="viewModel"></param>
 public void UnbindViewModelFromView(FrameworkElement frameworkElement, object viewModel)
 {
     if (viewModel is IParentDataContextAwareViewModel)
     {
         frameworkElement.Loaded -= InjectParentDataContextOnload;
     }
 }
Exemplo n.º 21
0
        public override IEnumerable<Timeline> CreateAnimation(FrameworkElement element)
        {
            var transform = GetTransform(element);

            var list = new List<Timeline>
            {
                element.AnimateProperty(AnimationProperty.Opacity)
                    .AddEasingKeyFrame(0.0, 0)
                    .AddEasingKeyFrame(Duration, 1),
            };
            if (Math.Abs(DistanceX) > 0)
            {
                list.Add(
                    element.AnimateProperty(AnimationProperty.TranslateX)
                        .AddEasingKeyFrame(0.0, transform.TranslateX + DistanceX)
                        .AddEasingKeyFrame(Duration, transform.TranslateX, new CubicEase()));
            }
            if (Math.Abs(DistanceY) > 0)
            {
                list.Add(
                    element.AnimateProperty(AnimationProperty.TranslateY)
                        .AddEasingKeyFrame(0.0, transform.TranslateY + DistanceY)
                        .AddEasingKeyFrame(Duration, transform.TranslateY, new CubicEase()));
            }

            return list;
        }
Exemplo n.º 22
0
        public static void UpdateClipSize(FrameworkElement element, Size clipSize)
        {
            if (element != null)
            {
                RectangleGeometry clipRectangle = null;

                if (element.Clip == null)
                {
                    clipRectangle = new RectangleGeometry();
                    element.Clip = clipRectangle;
                }
                else
                {
                    if (element.Clip is RectangleGeometry)
                    {
                        clipRectangle = (RectangleGeometry)element.Clip;
                    }
                }

                if (clipRectangle != null)
                {
                    clipRectangle.Rect = new Rect(new Point(0, 0), clipSize);
                }
            }
        }
Exemplo n.º 23
0
        /// <summary>
        /// Goes to specified visual state, waiting for the transition to complete.
        /// </summary>
        /// <param name="control">
        /// Control to transition.
        /// </param>
        /// <param name="visualStatesHost">
        /// FrameworkElement that defines the visual states
        /// (usually the root of the control's template).
        /// </param>
        /// <param name="stateGroupName">
        /// Name of the state group
        /// (speeds up the search for the state transition storyboard).
        /// </param>
        /// <param name="stateName">
        /// State to transition to.
        /// </param>
        /// <returns>
        /// Awaitable task that completes when the transition storyboard completes.
        /// </returns>
        /// <remarks>
        /// If a state transition storyboard is not found - the task
        /// completes immediately.
        /// </remarks>
        public static async Task GoToVisualStateAsync(
            this Control control,
            FrameworkElement visualStatesHost,
            string stateGroupName,
            string stateName)
        {
            var tcs = new TaskCompletionSource<Storyboard>();
            var storyboard = GetStoryboardForVisualState(visualStatesHost, stateGroupName, stateName);

            if (storyboard != null)
            {
                EventHandler eh = null;

                eh = (s, e) =>
                {
                    storyboard.Completed -= eh;
                    tcs.SetResult(storyboard);
                };

                storyboard.Completed += eh;
            }

            VisualStateManager.GoToState(control, stateName, true);

            if (storyboard == null)
            {
                return;
            }

            await tcs.Task;
        }
 public static SetterValueBindingHelper GetPropertyBinding(FrameworkElement element)
 {
     if (null == element)
     {
         throw new ArgumentNullException("element");
     }
     return (SetterValueBindingHelper)element.GetValue(PropertyBindingProperty);
 }
Exemplo n.º 25
0
 /// <summary>
 /// Unbind the view model loaded events
 /// </summary>
 /// <param name="frameworkElement"></param>
 /// <param name="viewModel"></param>
 public void UnbindViewModelFromView(FrameworkElement frameworkElement, object viewModel)
 {
     if (viewModel is ILoadedAwareViewModel)
     {
         frameworkElement.Loaded -= ViewModelOnLoaded;
         frameworkElement.Unloaded -= ViewModelOnUnloaded;
     }
 }
Exemplo n.º 26
0
 private ParentObserver(FrameworkElement view)
 {
     _view = ServiceProvider.WeakReferenceFactory(view);
     _parent = ToolkitExtensions.GetWeakReferenceOrDefault(FindParent(view), Empty.WeakReference, false);
     RoutedEventHandler handler = OnChanged;
     view.Loaded += handler;
     view.Unloaded += handler;
 }
 protected override void ApplyBindings(FrameworkElement attachedObject,
                                       IEnumerable<MvxBindingDescription> bindingDescriptions)
 {
     var binder = MvxBindingSingletonCache.Instance.Binder;
     var bindingDescriptionList = bindingDescriptions.ToList();
     var bindings = binder.Bind(attachedObject.DataContext, attachedObject, bindingDescriptionList);
     RegisterBindingsForUpdates(attachedObject, bindings);
 }
            public DependencyPropertyRegistration(FrameworkElement frameworkElement, DependencyProperty dependencyProperty, Action<object, object> propertyChangedCallback, object currentValue)
            {
                FrameworkElement = frameworkElement;
                DependencyProperty = dependencyProperty;
                PropertyChangedCallback = propertyChangedCallback;

                _currentValue = currentValue;
            }
 /// <summary>
 /// Causes the column cell being edited to revert to the specified value.
 /// </summary>
 /// <param name="editingElement">
 /// The element that the column displays for a cell in editing mode.
 /// </param>
 /// <param name="uneditedValue">
 /// The previous, unedited value in the cell being edited.
 /// </param>
 protected override void CancelCellEdit(FrameworkElement editingElement, object uneditedValue)
 {
     CheckBox editingCheckBox = editingElement as CheckBox;
     if (editingCheckBox != null)
     {
         editingCheckBox.IsChecked = (bool?)uneditedValue;
     }
 }
        /// <summary>
        /// Parse metadata from a target FrameworkElement.  This will cache the metadata on the element as an attached property.
        /// </summary>
        /// <param name="element">The target FrameworkElement to pull metadata from.</param>
        /// <param name="forceUpdate">If set, will not pull metadata from cache.</param>
        /// <param name="entity">The entity used.</param>
        /// <param name="bindingExpression">The bindingExpression used.</param>
        /// <returns>Returns the metadata associated with the element.  Will be null if no metadata was found.</returns>
        internal static ValidationMetadata ParseMetadata(FrameworkElement element, bool forceUpdate, out object entity, out BindingExpression bindingExpression)
        {
            entity = null;
            bindingExpression = null;
            if (element == null)
            {
                return null;
            }

            if (!forceUpdate)
            {
                ValidationMetadata existingVMD = element.GetValue(ValidationMetadataProperty) as ValidationMetadata;
                if (existingVMD != null)
                {
                    return existingVMD;
                }
            }

            BindingExpression be = null;
            FieldInfo[] fields = element.GetType().GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy);
            foreach (FieldInfo field in fields)
            {
                if (field.FieldType == typeof(DependencyProperty))
                {
                    // Found a dependency property
                    be = element.GetBindingExpression((DependencyProperty)field.GetValue(null));
                    if (be != null && be.ParentBinding != null && be.ParentBinding.Path != null)
                    {
                        // Found a BindingExpression, ensure it has valid data
                        entity = be.DataItem != null ? be.DataItem : element.DataContext;
                        if (entity != null)
                        {
                            if (be.ParentBinding.Mode == BindingMode.TwoWay)
                            {
                                bindingExpression = be;
                                // A twoway binding will be automatically chosen and the rest ignored
                                break;
                            }

                            // Perform an arbitrary sort on path (string), so the same dependency property is chosen consistently.
                            // Reflection ordering is not deterministic and if we just pick the first, we could be
                            // matched with different dependency properties depending on the run.
                            if (bindingExpression == null || string.Compare(be.ParentBinding.Path.Path, bindingExpression.ParentBinding.Path.Path, StringComparison.Ordinal) < 0)
                            {
                                bindingExpression = be;
                            }
                        }
                    }
                }
            }
            if (bindingExpression != null)
            {
                ValidationMetadata newVMD = ParseMetadata(bindingExpression.ParentBinding.Path.Path, entity);
                element.SetValue(ValidationMetadataProperty, newVMD);
                return newVMD;
            }
            return null;
        }
Exemplo n.º 31
0
        private async void Grid_Loading(FrameworkElement sender, object args)
        {
            createContacts();

            loadContacts();
        }
Exemplo n.º 32
0
 public static Size ArrangeElementWithSingleChild(FrameworkElement element, Size arrangeSize)
 {
     return(ArrangeElementWithSingleChild(element, arrangeSize, new Point(0, 0)));
 }
 private CutTooltipBehavior(FrameworkElement owner)
 {
     _owner = owner;
 }
        void AddNativeControls(NestedNativeControlGalleryPage page)
        {
            if (page.NativeControlsAdded)
            {
                return;
            }

            StackLayout sl = page.Layout;

            // Create and add a native TextBlock
            var originalText = "I am a native TextBlock";
            var textBlock    = new TextBlock
            {
                Text       = originalText,
                FontSize   = 14,
                FontFamily = new FontFamily("HelveticaNeue")
            };

            sl?.Children.Add(textBlock);

            // Create and add a native Button
            var button = new Windows.UI.Xaml.Controls.Button {
                Content = "Toggle Font Size", Height = 80
            };

            button.Click += (sender, args) => { textBlock.FontSize = textBlock.FontSize == 14 ? 24 : 14; };

            sl?.Children.Add(button.ToView());

            // Create a control which we know doesn't behave correctly with regard to measurement
            var difficultControl = new BrokenNativeControl
            {
                Text = "Not Sized/Arranged Properly"
            };

            var difficultControl2 = new BrokenNativeControl
            {
                Text = "Fixed"
            };

            // Add the misbehaving controls, one with a custom delegate for ArrangeOverrideDelegate
            sl?.Children.Add(difficultControl);
            sl?.Children.Add(difficultControl2,
                             arrangeOverrideDelegate: (renderer, finalSize) =>
            {
                if (finalSize.Width <= 0 || double.IsInfinity(finalSize.Width))
                {
                    return(null);
                }

                FrameworkElement frameworkElement = renderer.Control;

                frameworkElement.Measure(finalSize);

                // The broken control always tries to size itself to the screen width
                // So figure that out and we'll know how far off it's laying itself out
                WRect bounds       = ApplicationView.GetForCurrentView().VisibleBounds;
                double scaleFactor = DisplayInformation.GetForCurrentView().RawPixelsPerViewPixel;
                var screenWidth    = new Size(bounds.Width * scaleFactor, bounds.Height * scaleFactor);

                // We can re-center it by offsetting it during the Arrange call
                double diff = Math.Abs(screenWidth.Width - finalSize.Width) / -2;
                frameworkElement.Arrange(new WRect(diff, 0, finalSize.Width - diff, finalSize.Height));

                // Arranging the control to the left will make it show up past the edge of the stack layout
                // We can fix that by clipping it manually
                var clip = new RectangleGeometry {
                    Rect = new WRect(-diff, 0, finalSize.Width, finalSize.Height)
                };
                frameworkElement.Clip = clip;

                return(finalSize);
            }
                             );

            page.NativeControlsAdded = true;
        }
Exemplo n.º 35
0
 public static FrameworkElement GetRoot(FrameworkElement element)
 {
     return(FindRoot(element) as FrameworkElement);
 }
Exemplo n.º 36
0
 public static FrameworkElement FindElementByType(FrameworkElement treeRoot, Type type)
 {
     return(FindElement(treeRoot, element => element.GetType() == type));
 }
Exemplo n.º 37
0
 Point GetElementPositionRelatedToPopup(FrameworkElement element)
 {
     return(element.TransformToVisual(this).TransformPoint(new Point()));
 }
Exemplo n.º 38
0
 public static T FindElementByType <T>(FrameworkElement treeRoot) where T : FrameworkElement
 {
     return((T)FindElementByType(treeRoot, typeof(T)));
 }
Exemplo n.º 39
0
 protected override object PrepareCellForEdit(FrameworkElement editingElement, RoutedEventArgs editingEventArgs)
 {
     return(null);
 }
Exemplo n.º 40
0
 private static FrameworkElement FindTemplatedParent(FrameworkElement parent)
 {
     return(parent.TemplatedParent as FrameworkElement);
 }
Exemplo n.º 41
0
        public static bool TryFindNearestStatefulControl(FrameworkElement contextElement, out FrameworkElement resolvedControl)
        {
            FrameworkElement frameworkElement = contextElement;

            if (frameworkElement == null)
            {
                // TODO: should we throw an exception here? Tracked as spec issue 82282.
                resolvedControl = null;
                return(false);
            }

            // Try to find an element which is the immediate child of a UserControl, ControlTemplate or other such "boundary" element
            FrameworkElement parent = frameworkElement.Parent as FrameworkElement;
            bool             succesfullyResolved = true;

            // bubble up looking for a place to stop
            while (!HasVisualStateGroupsDefined(frameworkElement) && ShouldContinueTreeWalk(parent))
            {
                frameworkElement = parent;
                parent           = parent.Parent as FrameworkElement;
            }

            if (HasVisualStateGroupsDefined(frameworkElement))
            {
                if ((frameworkElement.TemplatedParent != null) && (frameworkElement.TemplatedParent is Control))
                {
                    // We didn't need to walk the tree to get this because TemplatedParent is set for all elements in the
                    // template.  However, it maintains consistency in our error checking to do it this way.
                    frameworkElement = frameworkElement.TemplatedParent as FrameworkElement;
                }
                else if (parent != null && parent is UserControl)
                {
                    // if our parent is a UserControl, then use that
                    frameworkElement = parent;
                }
            }
            else
            {
                succesfullyResolved = false;
            }

            resolvedControl = frameworkElement;
            return(succesfullyResolved);
        }
Exemplo n.º 42
0
 private static bool HasVisualStateGroupsDefined(FrameworkElement frameworkElement)
 {
     return(frameworkElement != null && VisualStateManager.GetVisualStateGroups(frameworkElement).Count != 0);
 }
Exemplo n.º 43
0
 /// <summary>
 /// Creates a new <see cref="T:System.Windows.Controls.UIElementCollection"/>.
 /// </summary>
 /// <param name="logicalParent">The logical parent element of the collection to be created.</param>
 /// <returns>
 /// An ordered collection of elements that have the specified logical parent.
 /// </returns>
 protected sealed override UIElementCollection CreateUIElementCollection(FrameworkElement logicalParent)
 {
     children = new UIChildrenCollection(this, logicalParent);
     return(children);
 }
Exemplo n.º 44
0
 protected override bool CommitCellEdit(FrameworkElement editingElement)
 {
     return(true);
 }
Exemplo n.º 45
0
        public static FrameworkElement Render(AdaptiveColumnSet columnSet, AdaptiveRenderContext context)
        {
            var uiColumnSet = new Grid();

            uiColumnSet.Style = context.GetStyle($"Adaptive.{columnSet.Type}");

            // Keep track of ContainerStyle.ForegroundColors before Container is rendered
            var outerStyle           = context.ForegroundColors;
            var parentContainerStyle = context.ParentStyle;

            if (columnSet.Style != null)
            {
                AdaptiveContainerRenderer.ApplyPadding(uiColumnSet, columnSet, parentContainerStyle, context);

                // Apply background color
                var columnSetStyle = context.Config.ContainerStyles.GetContainerStyleConfig(columnSet.Style);

                uiColumnSet.SetBackgroundColor(columnSetStyle.BackgroundColor, context);
                context.ForegroundColors = columnSetStyle.ForegroundColors;
            }

            AdaptiveContainerStyle columnSetContainerStyle = columnSet.Style ?? parentContainerStyle;

            if (columnSetContainerStyle == AdaptiveContainerStyle.None)
            {
                columnSetContainerStyle = parentContainerStyle;
            }
            context.ParentStyle = columnSetContainerStyle;

            foreach (var column in columnSet.Columns)
            {
                FrameworkElement uiContainer = context.Render(column);

                // Add vertical Seperator
                if (uiColumnSet.ColumnDefinitions.Count > 0)
                {
                    if (column.Separator || column.Spacing != AdaptiveSpacing.None)
                    {
                        var uiSep = new Grid();
                        uiSep.Style = context.GetStyle($"Adaptive.VerticalSeparator");

                        uiSep.VerticalAlignment = VerticalAlignment.Stretch;

                        int spacing = context.Config.GetSpacing(column.Spacing);
                        uiSep.Margin = new Thickness(spacing / 2.0, 0, spacing / 2.0, 0);

                        uiSep.Width = context.Config.Separator.LineThickness;
                        if (column.Separator && context.Config.Separator.LineColor != null)
                        {
                            uiSep.Background = context.GetColorBrush(context.Config.Separator.LineColor);
                        }

                        uiColumnSet.ColumnDefinitions.Add(new ColumnDefinition()
                        {
                            Width = GridLength.Auto
                        });
                        Grid.SetColumn(uiSep, uiColumnSet.ColumnDefinitions.Count - 1);
                        uiColumnSet.Children.Add(uiSep);
                    }
                }

                // do some sizing magic using the magic GridUnitType.Star
                var width = column.Width?.ToLower();
                if (string.IsNullOrEmpty(width))
#pragma warning disable CS0618 // Type or member is obsolete
                {
                    width = column.Size?.ToLower();
                }
#pragma warning restore CS0618 // Type or member is obsolete
                if (width == null || width == AdaptiveColumnWidth.Stretch.ToLower())
                {
                    uiColumnSet.ColumnDefinitions.Add(new ColumnDefinition()
                    {
                        Width = new GridLength(1, GridUnitType.Star)
                    });
                }
                else if (width == AdaptiveColumnWidth.Auto.ToLower())
                {
                    uiColumnSet.ColumnDefinitions.Add(new ColumnDefinition()
                    {
                        Width = GridLength.Auto
                    });
                }
                else
                {
                    if (double.TryParse(width, out double val) && val >= 0)
                    {
                        // Weighted proportion (number only)
                        uiColumnSet.ColumnDefinitions.Add(new ColumnDefinition()
                        {
                            Width = new GridLength(val, GridUnitType.Star)
                        });
                    }
                    else if (width.EndsWith("px") && double.TryParse(width.Substring(0, width.Length - 2), out double pxVal) && pxVal >= 0)
                    {
                        // Exact pixel (number followed by "px")
                        uiColumnSet.ColumnDefinitions.Add(new ColumnDefinition()
                        {
                            Width = new GridLength((int)pxVal, GridUnitType.Pixel)
                        });
                    }
                    else
                    {
                        uiColumnSet.ColumnDefinitions.Add(new ColumnDefinition()
                        {
                            Width = GridLength.Auto
                        });
                    }
                }

                Grid.SetColumn(uiContainer, uiColumnSet.ColumnDefinitions.Count - 1);
                uiColumnSet.Children.Add(uiContainer);
            }

            if (columnSet.SelectAction != null)
            {
                return(context.RenderSelectAction(columnSet.SelectAction, uiColumnSet));
            }

            if (!columnSet.IsVisible)
            {
                uiColumnSet.Visibility = Visibility.Collapsed;
            }

            // Revert context's value to that of outside the Container
            context.ForegroundColors = outerStyle;
            context.ParentStyle      = parentContainerStyle;

            return(uiColumnSet);
        }
Exemplo n.º 46
0
 protected override void CancelCellEdit(FrameworkElement editingElement, object uneditedValue)
 {
 }
Exemplo n.º 47
0
        private void Rotary_ManipulationStarting(object sender, ManipulationStartingRoutedEventArgs e)
        {
            FrameworkElement element = sender as FrameworkElement;

            e.Pivot = new ManipulationPivot(element.Center(), element.ActualWidth / 2.0);
        }
Exemplo n.º 48
0
 /// <summary>
 /// Called when child is added.
 /// </summary>
 /// <param name="child">The added child.</param>
 protected internal virtual void OnChildAdded(FrameworkElement child)
 {
 }
Exemplo n.º 49
0
 public static FrameworkElement FindElementByName(FrameworkElement treeRoot, string name)
 {
     return(FindElement(treeRoot, element => element.Name == name));
 }
Exemplo n.º 50
0
 private static void UnsubscribeFromEvents(FrameworkElement element)
 {
     DragDropManager.RemoveDragInitializeHandler(element, OnElementDragInitialize);
     DragDropManager.RemoveDragDropCompletedHandler(element, OnElementDragDropCompleted);
     element.Unloaded -= OnElementUnloaded;
 }
 /// <summary>
 /// The animation method that is fired when the value changes
 /// </summary>
 /// <param name="element">The element</param>
 /// <param name="value">The new value</param>
 protected virtual void DoAnimation(FrameworkElement element, bool value)
 {
 }
Exemplo n.º 52
0
 /// <summary>
 /// Assume adornments can't have their own adornments.
 /// </summary>
 /// <param name="selelt"></param>
 /// <param name="templ"></param>
 /// <returns></returns>
 public override Adornment MakeAdornment(FrameworkElement selelt, DataTemplate templ)
 {
     return(null);
 }
Exemplo n.º 53
0
        public WidthService(TextBlock tblTitle, TextBlock tblArtist, ColumnDefinition cdSong, FrameworkElement slider)
        {
            this.tblTitle  = tblTitle;
            this.tblArtist = tblArtist;
            this.cdSong    = cdSong;
            this.slider    = slider;

            var tblDPD = DependencyPropertyDescriptor.FromProperty(TextBlock.TextProperty, typeof(TextBlock));

            tblDPD.AddValueChanged(tblTitle, OnReset);
            tblDPD.AddValueChanged(tblArtist, OnReset);

            var cdDPD = DependencyPropertyDescriptor.FromProperty(FrameworkElement.ActualWidthProperty, typeof(FrameworkElement));

            cdDPD.AddValueChanged(slider, OnUpdate);
        }
		/// <summary>Construct FeatureLayerFromLocalGeodatabase sample control</summary>
		public FeatureLayerFromShapefile()
		{
			InitializeComponent();
			_featureOverlay = MyMapView.Overlays.Items[0] as FrameworkElement;
			MyMapView.MapViewTapped += MyMapView_MapViewTapped;
		}
Exemplo n.º 55
0
        public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            FrameworkElement element = container as FrameworkElement;

            return((DataTemplate)element.FindResource("DataTempate_Normal"));
        }
Exemplo n.º 56
0
        public void BeginAnimateScore(double newValue, FrameworkElement parent)
        {
            if (newValue != this.CurrentValue)
            {
                lock (this)
                {
                    if (newValue != this.CurrentValue)
                    {
                        var boostTransparentAnimation = new DoubleAnimation(newValue, BoostDuration)
                        {
                            EasingFunction = EasingFunction
                        };
                        Storyboard.SetTargetName(boostTransparentAnimation, this.boostBarTransparentStopName);
                        Storyboard.SetTargetProperty(boostTransparentAnimation, new PropertyPath(GradientStop.OffsetProperty));

                        var boostStopAnimation = new DoubleAnimation(newValue, BoostDuration)
                        {
                            EasingFunction = EasingFunction
                        };
                        Storyboard.SetTargetName(boostStopAnimation, this.boostBarBlackStopName);
                        Storyboard.SetTargetProperty(boostStopAnimation, new PropertyPath(GradientStop.OffsetProperty));

                        var scoreTransparentAnimation = new DoubleAnimation(newValue, ScoreDuration)
                        {
                            EasingFunction = EasingFunction
                        };
                        Storyboard.SetTargetName(scoreTransparentAnimation, this.scoreBarTransparentStopName);
                        Storyboard.SetTargetProperty(scoreTransparentAnimation, new PropertyPath(GradientStop.OffsetProperty));

                        var scoreStopAnimation = new DoubleAnimation(newValue, ScoreDuration)
                        {
                            EasingFunction = EasingFunction
                        };
                        Storyboard.SetTargetName(scoreStopAnimation, this.scoreBarBlackStopName);
                        Storyboard.SetTargetProperty(scoreStopAnimation, new PropertyPath(GradientStop.OffsetProperty));

                        if (newValue > this.CurrentValue)
                        {
                            boostStopAnimation.BeginTime        = BoostStopDelayDuration;
                            scoreTransparentAnimation.BeginTime = ScoreStartDelayDuration;
                            scoreStopAnimation.BeginTime        = ScoreStartDelayDuration + ScoreStopDelayDuration;
                        }
                        else
                        {
                            scoreTransparentAnimation.BeginTime = BoostStopDelayDuration;
                            boostStopAnimation.BeginTime        = ScoreStartDelayDuration;
                            boostTransparentAnimation.BeginTime = ScoreStartDelayDuration + ScoreStopDelayDuration;
                        }

                        var storyboard = new Storyboard();
                        storyboard.Children.Add(boostTransparentAnimation);
                        storyboard.Children.Add(boostStopAnimation);
                        storyboard.Children.Add(scoreTransparentAnimation);
                        storyboard.Children.Add(scoreStopAnimation);
                        storyboard.Begin(parent);

                        this.CurrentValue = newValue;
                    }
                }
            }
        }
Exemplo n.º 57
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="AnimationItem" /> class.
 /// </summary>
 /// <param name="element">The element.</param>
 /// <param name="animation">The animation.</param>
 public AnimationItem(FrameworkElement element, AnimationTimeline animation)
 {
     this.Element   = element;
     this.Animation = animation;
 }
Exemplo n.º 58
0
 private static void ParseRectangle(FrameworkElement element)
 {
     _currentObject.AddRenderableElement(new RenderableRectangle(element));
 }
Exemplo n.º 59
0
        public static bool IsPointInsideElementBounds(Point position, FrameworkElement element, Thickness margin)
        {
            Rect rect = new Rect(-margin.Left, -margin.Top, element.ActualWidth + margin.Right + margin.Left, element.ActualHeight + margin.Bottom + margin.Top);

            return(rect.Contains(position));
        }
        /// <summary>
        ///     Set the Icon to the underlying TrayIcon.Icon
        /// </summary>
        public void SetIcon(FrameworkElement value)
        {
            var taskbarIcon = TrayIcon as FrameworkElement;

            taskbarIcon?.SetCurrentValue(FrameworkElementIcon.ValueProperty, value);
        }