Example #1
0
        public Enemy(Field field, FrameworkElement ui)
            : base(ui)
        {
            this.field = field;

            this.right = -ui.ActualWidth;
            this.bottom = (double)App.Random.Next(100);
            ui.SetValue(Canvas.RightProperty, this.right);
            ui.SetValue(Canvas.BottomProperty, this.bottom);
        }
Example #2
0
		protected override void SetCommonBindings(FrameworkElement marker)
		{
			base.SetCommonBindings(marker);

			marker.SetValue(ViewportPanel.YProperty, 0.0);
			marker.SetBinding(ViewportPanel.ViewportHeightProperty, DependentValueBinding);
			marker.SetBinding(ViewportPanel.ViewportWidthProperty, ColumnWidthBinding);
			marker.SetValue(ViewportPanel.ViewportVerticalAlignmentProperty, VerticalAlignment.Bottom);
			marker.SetBinding(ViewportPanel.XProperty, IndexBinding);
		}
		protected override void AddCommonBindings(FrameworkElement marker)
		{
			base.AddCommonBindings(marker);

			marker.SetValue(ViewportPanel.XProperty, 0.0);
			marker.SetBinding(ViewportPanel.ViewportWidthProperty, viewportWidthBinding);
			marker.SetValue(ViewportPanel.ViewportHeightProperty, 0.85);
			marker.SetValue(ViewportPanel.ViewportHorizontalAlignmentProperty, HorizontalAlignment.Left);
			marker.SetBinding(ViewportPanel.YProperty, viewportYBinding);
		}
Example #4
0
		public static void SetupNextToolTip(FrameworkElement element, Window window) {
			element.ToolTip = GetNextToolTip(window);

			if (element.ToolTip != null) {
				element.SetValue(ToolTipService.ShowDurationProperty, 30000);
			}
		}
Example #5
0
        public void FreezableBasicTest()
        {
            int resourcesChangedCount = 0;
            object resourceValue;

            Freezable freezable = new Freezable();
            freezable.ResourcesChanged += (sender, e) => resourcesChangedCount++;

            FrameworkElement element = new FrameworkElement();
            element.DataContext = "data-context";
            element.Resources = new ResourceDictionary();
            element.Resources.Add("key1", "value1");

            Assert.AreNotEqual("data-context", freezable.GetValue(FrameworkElement.DataContextProperty));
            Assert.IsFalse(freezable.TryGetResource("key1", out resourceValue));

            element.SetValue(ValueProperty, freezable);
            Assert.AreEqual("data-context", freezable.GetValue(FrameworkElement.DataContextProperty));
            Assert.AreEqual(1, resourcesChangedCount);
            Assert.IsTrue(freezable.TryGetResource("key1", out resourceValue));
            Assert.AreEqual("value1", resourceValue);

            element.Resources.Add("key2", "value2");
            Assert.AreEqual(2, resourcesChangedCount);
            Assert.IsTrue(freezable.TryGetResource("key2", out resourceValue));
            Assert.AreEqual("value2", resourceValue);
        }
    internal void UpdateProperty( FrameworkElement element, DependencyProperty elementProp, DependencyProperty definitionProperty )
    {
      object currentValue = this.GetValue( definitionProperty );
      object localValue = this.ReadLocalValue( definitionProperty );
      object elementValue = element.GetValue( elementProp );
      bool areEquals = false;

      // Avoid setting values if it does not affect anything 
      // because setting a local value may prevent a style setter from being active.
      if( localValue != DependencyProperty.UnsetValue )
      {
        if( ( elementValue != null ) && ( currentValue != null ) )
        {
          areEquals = ( elementValue.GetType().IsValueType && currentValue.GetType().IsValueType )
                      ? elementValue.Equals( currentValue )  // Value Types
                      : currentValue == element.GetValue( elementProp ); // Reference Types
        }

        if( !areEquals )
        {
          element.SetValue( elementProp, currentValue );
        }
        else
        {
          element.ClearValue( elementProp );
        }
      }
    }
 public void InjectControl(FrameworkElement pControl)
 {
     _panel.Dispatcher.Invoke(() =>
     {
         pControl.SetValue(DockPanel.DockProperty, Dock.Left);
         _panel.Children.Insert(1, pControl);
     });
 }
Example #8
0
 public static void SetDefaultSource(FrameworkElement image, string value)
 {
     if (image == null)
     {
         throw new ArgumentNullException("Image");
     }
     image.SetValue(ImageDecoder.DefaultSourceProperty, value);
 }
 private static void SetHasBeenStyled(FrameworkElement element, bool value)
 {
     if (element == null)
     {
         throw new ArgumentNullException("element");
     }
     element.SetValue(HasBeenStyledProperty, value);
 }
Example #10
0
        private static void SetPosition(FrameworkElement ellipse, double offset,
            double posOffSet, double step, double ew, double eh, double w, double h,
            double r)
        {
            double t = 2*Math.PI*posOffSet/10;
            ellipse.Width = ew;
            ellipse.Height = eh;

            ellipse.SetValue(Canvas.LeftProperty, w + r*Math.Cos(t));
            ellipse.SetValue(Canvas.TopProperty, h + r*Math.Sin(t));

            //ellipse.SetValue(Canvas.LeftProperty,w
            //    + Math.Sin(offset + posOffSet * step) * w);

            //ellipse.SetValue(Canvas.TopProperty, h
            //    + Math.Cos(offset + posOffSet * step) * h);
        }
Example #11
0
 public static PushBindingCollection GetPushBindings(FrameworkElement obj)
 {
     if (obj.GetValue(PushBindingsProperty) == null)
     {
         obj.SetValue(PushBindingsProperty, new PushBindingCollection(obj));
     }
     return (PushBindingCollection)obj.GetValue(PushBindingsProperty);
 }
 /// <summary>
 /// Sets the value of the IsConfigurable attached property to a specified FrameworkElement.
 /// </summary>
 /// <param name="element">The FrameworkElement to which the attached property is written.</param>
 /// <param name="value">The needed IsConfigurable value.</param>
 public static void SetIsConfigurable(FrameworkElement element, bool value)
 {
     if (element == null)
     {
         throw new ArgumentNullException("element");
     }
     element.SetValue(IsConfigurableProperty, value);
 }
Example #13
0
 public static void SetFill(FrameworkElement element, bool value)
 {
     if (element == null)
     {
         throw new ArgumentNullException("element");
     }
     element.SetValue(ZoomScrollViewer.FillProperty, value);
 }
        public static void SetObserve(FrameworkElement frameworkElement, bool observe)
        {
            if (frameworkElement == null)
            {
                throw new ArgumentNullException("frameworkElement");
            }

            frameworkElement.SetValue(ObserveProperty, observe);
        }
        public static void SetObservedHeight(FrameworkElement frameworkElement, double observedHeight)
        {
            if (frameworkElement == null)
            {
                throw new ArgumentNullException("frameworkElement");
            }

            frameworkElement.SetValue(ObservedHeightProperty, observedHeight);
        }
		protected override void AddCommonBindings(FrameworkElement marker)
		{
			base.AddCommonBindings(marker);

			marker.SetValue(ViewportPanel.YProperty, 0.0);

			if (!String.IsNullOrEmpty(DependentValuePath))
			{
				viewportHeightBinding = new Binding(DependentValuePath);
			}

			marker.SetBinding(ViewportPanel.ViewportHeightProperty, viewportHeightBinding);

			if (ViewportPanel.GetViewportWidth(marker).IsNaN())
				marker.SetValue(ViewportPanel.ViewportWidthProperty, 0.85);
			marker.SetValue(ViewportPanel.ViewportVerticalAlignmentProperty, VerticalAlignment.Bottom);
			marker.SetBinding(ViewportPanel.XProperty, viewportXBinding);
		}
Example #17
0
 /// <summary>Captures a snapshot of the source element as a bitmap image. The snapshot is created based on the specified rendering parameters.</summary>
 /// <param name="sourceElement">The source element.</param>
 /// <param name="bitmapSize">The bitmap size.</param>
 /// <param name="scalingMode">The bitmap scaling mode.</param>
 /// <param name="bitmapDpi">The bitmap dpi.</param>
 /// <param name="pixelFormat">The bitmap pixel format.</param>
 /// <returns>The snapshot of the source element.</returns>
 public static BitmapSource CaptureSnapshot(FrameworkElement sourceElement, Size bitmapSize, BitmapScalingMode scalingMode, Vector bitmapDpi, PixelFormat pixelFormat) {
    if (sourceElement == null || bitmapSize.IsZero()) return null;
    var snapshot = new RenderTargetBitmap((int)bitmapSize.Width, (int)bitmapSize.Height, bitmapDpi.X, bitmapDpi.Y, pixelFormat);
    sourceElement.SetValue(RenderOptions.BitmapScalingModeProperty, scalingMode);
    snapshot.Render(sourceElement);
    sourceElement.ClearValue(RenderOptions.BitmapScalingModeProperty);
    snapshot.Freeze();
    return snapshot;
 }
Example #18
0
 public static void SetHwndBackgroundBrush(FrameworkElement window, SolidColorBrush value)
 {
     if (!(window is Window))
     {
         return;
     }
     Verify.IsNotNull(window, "window");
     window.SetValue(HwndBackgroundBrushProperty, value);
 }
        internal static void UnSet(FrameworkElement element)
        {
            var hook = element.GetValue(VisualStateManagerHookProperty) as VisualStateManagerHook;

            if (hook != null)
            {
                element.SetValue(VisualStateManagerHookProperty, null);
                hook.Dispose();
            }
        }
Example #20
0
		public static void SetToolTip(DbAttribute attribute, FrameworkElement label) {
			string description;

			if (!String.IsNullOrEmpty(attribute.Description)) {
				description = attribute.Description;

				TextBlock block = new TextBlock();
				block.Text = description;
				block.TextWrapping = TextWrapping.Wrap;
				block.MaxWidth = 300;
				label.ToolTip = block;
				label.SetValue(ToolTipService.ShowDurationProperty, 30000);
			}
		}
Example #21
0
 public static bool ExecuteOnLoad(FrameworkElement element, RoutedEventHandler handler)
 {
     if ((bool) element.GetValue(IsLoadedProperty))
     {
         handler(element, new RoutedEventArgs());
         return true;
     }
     RoutedEventHandler loaded = null;
     loaded = delegate (object s, RoutedEventArgs e) {
         element.SetValue(IsLoadedProperty, true);
         handler(s, e);
         element.Loaded -= loaded;
     };
     element.Loaded += loaded;
     return false;
 }
 internal void UpdateProperty( FrameworkElement element, DependencyProperty elementProp, DependencyProperty definitionProperty )
 {
     object currentValue = this.GetValue( definitionProperty );
       object localValue = this.ReadLocalValue( definitionProperty );
       // Avoid setting values if it does not affect anything
       // because setting a local value may prevent a style setter from being active.
       if( ( localValue != DependencyProperty.UnsetValue )
     || currentValue != element.GetValue( elementProp ) )
       {
     element.SetValue( elementProp, currentValue );
       }
       else
       {
     element.ClearValue( elementProp );
       }
 }
        public void ResourceReferenceExpressionBaseTest()
        {
            FrameworkElement root = new FrameworkElement();
            FrameworkElement child1 = new FrameworkElement();
            FrameworkElement child2 = new FrameworkElement();

            child1.AddVisualChild(child2);

            int testValueChanged = 0;
            child2.PropertyChanged += (sender, e) => testValueChanged += e.Property == TestValueProperty ? 1 : 0;

            child2.SetValue(TestValueProperty, new ResourceReferenceExpressionProvider("key1"));

            Assert.AreEqual("default", child2.GetValue(TestValueProperty));
            Assert.AreEqual(0, testValueChanged);

            root.Resources = new ResourceDictionary();
            root.Resources.Add("key1", "value1");
            root.AddVisualChild(child1);

            Assert.AreEqual("value1", child2.GetValue(TestValueProperty));
            Assert.AreEqual(1, testValueChanged);

            root.Resources.Remove("key1");

            Assert.AreEqual("default", child2.GetValue(TestValueProperty));
            Assert.AreEqual(2, testValueChanged);

            ResourceDictionary dictionary = new ResourceDictionary();
            dictionary.Add("key1", "value2");

            root.Resources.MergedDictionaries.Add(dictionary);

            Assert.AreEqual("value2", child2.GetValue(TestValueProperty));
            Assert.AreEqual(3, testValueChanged);

            child1.Resources = new ResourceDictionary();
            child1.Resources.Add("key1", "value3");

            Assert.AreEqual("value3", child2.GetValue(TestValueProperty));
            Assert.AreEqual(4, testValueChanged);

            child1.Resources.Remove("key1");

            Assert.AreEqual("value2", child2.GetValue(TestValueProperty));
            Assert.AreEqual(5, testValueChanged);
        }
        partial void InitializeBusyIndicator()
        {
            if (_busyIndicator != null)
            {
                return;
            }

            _grid = new Grid();
            _grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) });
            _grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) });
            _grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) });
            _grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) });

            var backgroundBorder = new Border();
            backgroundBorder.Background = new SolidColorBrush(Colors.Gray);
            backgroundBorder.Opacity = 0.5;
            backgroundBorder.SetValue(Grid.RowSpanProperty, 4);
            _grid.Children.Add(backgroundBorder);

            _statusTextBlock = new TextBlock();
            _statusTextBlock.Style = (Style)Application.Current.Resources["PhoneTextNormalStyle"];
            _statusTextBlock.HorizontalAlignment = HorizontalAlignment.Center;
            _statusTextBlock.SetValue(Grid.RowProperty, 1);
            _grid.Children.Add(_statusTextBlock);

            _busyIndicator = ConstructBusyIndicator();
            _busyIndicator.SetValue(Grid.RowProperty, 2);
            _grid.Children.Add(_busyIndicator);

            _containerPopup = new Popup();
            _containerPopup.VerticalAlignment = VerticalAlignment.Center;
            _containerPopup.HorizontalAlignment = HorizontalAlignment.Center;
            _containerPopup.Child = _grid;

            double rootWidth = Application.Current.Host.Content.ActualWidth;
            double rootHeight = Application.Current.Host.Content.ActualHeight;

            _busyIndicator.Width = rootWidth;

            _grid.Width = rootWidth;
            _grid.Height = rootHeight;

            _containerPopup.UpdateLayout();

            return;
        }
        /// <summary>
        /// Registers the command.
        /// </summary>
        /// <param name="commandName">The command name.</param>
        /// <param name="element">The element.</param>
        internal static void RegisterCommand(string commandName, FrameworkElement element)
        {
            var cmd = CommandService.FindCommand(commandName);
            if (cmd != null)
            {
                var subscription = cmd.CreateCommandSubscription(element, commandName);

                var elementSubscriptions = element.GetValue(CommandSubscriptionProperty) as Dictionary<string, CommandSubscription>;
                if (elementSubscriptions == null)
                {
                    elementSubscriptions = new Dictionary<string, CommandSubscription>();
                    element.SetValue(CommandSubscriptionProperty, elementSubscriptions);
                }

                subscription.HookEvents();
                elementSubscriptions[commandName] = subscription;
            }
        }
Example #26
0
		public static void ApplyTemplate(FrameworkElement item, ImageBrush brush, ContentControl contentBody, Stretch stretch, DependencyProperty imageDependencyProperty)
		{
			SetStretch(brush, stretch);

			if (contentBody != null)
			{
				var bottom = -(contentBody.FontSize / 8.0);
				var top = -(contentBody.FontSize / 2.0) - bottom;

				contentBody.Margin = new Thickness(0, top, 0, bottom);
			}
			
			var image = item.GetValue(imageDependencyProperty) as ImageSource;

			if (image == null)
				item.SetValue(imageDependencyProperty, new BitmapImage(new Uri("/Coding4Fun.Phone.Controls;component/Media/icons/appbar.check.rest.png", UriKind.RelativeOrAbsolute)));
			else 
				SetImageBrush(brush, image);
		}
        public void UnregisterFrameworkElementUsingAttachedProperty()
        {
            // ARRANGE
            var frameworkElement = new FrameworkElement();
            

            var window = new Window
            {
                Content = frameworkElement
            };

            frameworkElement.SetValue(DialogServiceViews.IsRegisteredProperty, true);
            
            // ACT
            frameworkElement.SetValue(DialogServiceViews.IsRegisteredProperty, false);

            // ASSERT
            Assert.That(DialogServiceViews.Views, Is.Empty);
        }
Example #28
0
        private SuperCursor(FrameworkElement element, DataTemplate template)
		{
			_element = element;
            element.SetValue(SuperCursorProperty, this);
			_originalCursor = element.Cursor;
			element.Cursor = Cursors.None;
			element.MouseLeave += element_MouseLeave;
			element.MouseMove += element_MouseMove;
            _cursorContainer = new Popup
            {
                IsOpen = false,
                Child = new ContentControl
                {
                    ContentTemplate = template,
                    IsHitTestVisible = false,
                    RenderTransform = new TranslateTransform()
                },
                IsHitTestVisible = false
            };
		}
Example #29
0
 private CustomCursor(FrameworkElement element, DataTemplate template)
 {
     this.element = element;
     element.SetValue(CustomCursorProperty, this);
     originalCursor = element.Cursor;
     element.Cursor = Cursors.None;
     element.MouseLeave += element_MouseLeave;
     element.MouseMove += element_MouseMove;
     cursorContainer = new System.Windows.Controls.Primitives.Popup()
     {
         IsOpen = false,
         Child = new ContentControl()
         {
             ContentTemplate = template,
             IsHitTestVisible = false,
             RenderTransform = new TranslateTransform()
         }
     };
     cursorContainer.IsHitTestVisible = false;
 }
        internal static LabelValidationMetadata ParseMetadata(FrameworkElement element, bool forceUpdate, out object entity, out BindingExpression bindingExpression)
        {
            entity = (object)null;
            bindingExpression = (BindingExpression)null;
            if (element == null)
                return (LabelValidationMetadata)null;
            if (!forceUpdate)
            {
                LabelValidationMetadata validationMetadata = element.GetValue(LabelValidationHelper.ValidationMetadataProperty) as LabelValidationMetadata;
                if (validationMetadata != null)
                    return validationMetadata;
            }
            foreach (FieldInfo fieldInfo in element.GetType().GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy))
            {
                if (fieldInfo.FieldType == typeof(DependencyProperty))
                {
                    BindingExpression bindingExpression1 = element.GetBindingExpression((DependencyProperty)fieldInfo.GetValue((object)null));
                    if (bindingExpression1 != null && bindingExpression1.ParentBinding != null && bindingExpression1.ParentBinding.Path != null)
                    {
                        entity = bindingExpression1.DataItem ?? element.DataContext;
                        if (entity != null)
                        {
                            if (bindingExpression1.ParentBinding.Mode == BindingMode.TwoWay)
                            {
                                bindingExpression = bindingExpression1;
                                break;
                            }
                            else if (bindingExpression == null || string.Compare(bindingExpression1.ParentBinding.Path.Path, bindingExpression.ParentBinding.Path.Path, StringComparison.Ordinal) < 0)
                                bindingExpression = bindingExpression1;
                        }
                    }
                }
            }

            if (bindingExpression == null)
                return null;

            LabelValidationMetadata validationMetadata1 = ParseMetadata(bindingExpression.ParentBinding.Path.Path, entity);
            element.SetValue(ValidationMetadataProperty, (object)validationMetadata1);
            return validationMetadata1;
        }
Example #31
0
        public static void BreakGroup(SchemaView view)
        {
            Canvas  parent = (Canvas)view.MainPanel;
            Viewbox g      = view.SelectionManager.SelectedObjects[0] as Viewbox;

            try
            {
                Canvas gc = (Canvas)g.Child;

                while (gc.Children.Count > 0)
                {
                    System.Windows.FrameworkElement child = gc.Children[0] as System.Windows.FrameworkElement;

                    //this code need for ungrouping not stretched shapes
                    child.SetValue(System.Windows.Controls.Panel.MarginProperty, System.Windows.DependencyProperty.UnsetValue);
                    //Rect b=VisualTreeHelper.GetContentBounds(child);
                    Rect   b    = VisualTreeHelper.GetDescendantBounds(child);
                    double left = Canvas.GetLeft(child);
                    double top  = Canvas.GetTop(child);

                    left = double.IsNaN(left) ? 0 : left;
                    top  = double.IsNaN(top) ? 0 : top;


                    if ((child is Shape) && child.ReadLocalValue(System.Windows.Shapes.Shape.StretchProperty).Equals(System.Windows.DependencyProperty.UnsetValue))
                    {
                        child.Width  = b.Width;
                        child.Height = b.Height;
                        Canvas.SetLeft(child, left + b.X);
                        Canvas.SetTop(child, top + b.Y);


                        child.SetValue(System.Windows.Shapes.Shape.StretchProperty, System.Windows.Media.Stretch.Fill);
                        gc.UpdateLayout();
                    }
                    // excluding rotate from common matrix
                    // need to separate scale*skew matrix on scale and transform transformations

                    Matrix matrGtr = ((Transform)child.TransformToVisual(parent)).Value;


                    double x = matrGtr.OffsetX;
                    double y = matrGtr.OffsetY;

                    double angleY = Math.Atan(matrGtr.M12 / matrGtr.M11) * 180 / Math.PI;
                    matrGtr.OffsetY = 0; matrGtr.OffsetX = 0;

                    RotateTransform rt = new RotateTransform(angleY);
                    matrGtr.Rotate(-angleY);
                    TransformGroup gtr = new TransformGroup();
                    gtr.Children.Add(new MatrixTransform(matrGtr));
                    gtr.Children.Add(rt);
                    child.RenderTransform = gtr;

                    child.RenderTransformOrigin = new Point(0.5, 0.5);

                    Point pO = new Point(child.Width * child.RenderTransformOrigin.X, child.Height * child.RenderTransformOrigin.Y);
                    Point p  = gtr.Transform(pO);
                    Canvas.SetLeft(child, x - (pO - p).X);
                    Canvas.SetTop(child, y - (pO - p).Y);

                    gc.Children.Remove(child);
                    parent.Children.Add(child);
                    //tool.NotifyObjectCreated(child);
                }
                g.Child = null;
                //tool.NotifyObjectDeleted(g);
                parent.Children.Remove(g);
                view.SelectionManager.SelectObject(null);
            }
            catch (Exception)
            {
            }
        }
Example #32
0
 public static void SetSetDpi(System.Windows.FrameworkElement element, bool value) => element.SetValue(SetDpiProperty, value);