public static void SetTextProperties(
     this DependencyObject dependencyObject,
     TextFormattingRunProperties textProperties
     )
 {
     DependencyObjectExtensions.SetTextProperties(dependencyObject, textProperties);
 }
예제 #2
0
        private static void ValidateDropdownApply(object sender, RoutedEventArgs e)
        {
            var grid        = DependencyObjectExtensions.GetParent <Grid>((ComboBox)sender);
            var applyButton = grid.FirstOrDefaultChild <Button>(c => c.Content.ToString() == "Apply");

            applyButton.IsEnabled = true;
        }
예제 #3
0
        partial void RegisterEvents()
        {
            _touchSubscription.Disposable = null;

            View uiControl = GetUIControl();

            var nativeButton = uiControl as Android.Widget.Button;

            if (nativeButton is Android.Widget.Button)
            {
                _isEnabledSubscription.Disposable =
                    DependencyObjectExtensions.RegisterDisposablePropertyChangedCallback(
                        this,
                        IsEnabledProperty,
                        (s, e) => uiControl.Enabled = IsEnabled
                        );

                uiControl.Enabled = IsEnabled;
            }
            else if (uiControl != null)
            {
            }
            else
            {
                if (this.Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug))
                {
                    this.Log().WarnFormat("ControlTemplateRoot is not available, {0} will not be clickable", this.GetType());
                }
            }
        }
 public static void SetDefaultTextProperties(
     this DependencyObject dependencyObject,
     IClassificationFormatMap formatMap
     )
 {
     DependencyObjectExtensions.SetDefaultTextProperties(dependencyObject, formatMap);
 }
예제 #5
0
        // change the error text to something more useful
        private static void ChangeErrorText(Rectangle rect)
        {
            var window     = DependencyObjectExtensions.GetParent <Window>(rect);
            var errorBlock = window.FirstOrDefaultChild <TextBlock>(w => w.Name == "ErrorBlock");

            errorBlock.Text       = "\n Please place all your ships first!";
            errorBlock.Visibility = Visibility.Visible;
        }
예제 #6
0
        partial void RegisterEvents()
        {
            _touchSubscription.Disposable     = null;
            _isEnabledSubscription.Disposable = null;

            View uiControl = GetUIControl();

            var nativeButton = uiControl as Android.Widget.Button;

            if (nativeButton is Android.Widget.Button)
            {
                this.Log().Debug("Template contains Android.Widget.Button, hooking up to Click and syncing IsEnabled state");

                _touchSubscription.Disposable = uiControl
                                                .RegisterClick((e, s) =>
                {
                    if (this.Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug))
                    {
                        this.Log().Debug("TouchUpInside, executing command");
                    }

                    OnClick();
                });

                _isEnabledSubscription.Disposable =
                    DependencyObjectExtensions.RegisterDisposablePropertyChangedCallback(
                        this,
                        IsEnabledProperty,
                        (s, e) => uiControl.Enabled = IsEnabled
                        );

                uiControl.Enabled = IsEnabled;
            }
            else if (uiControl != null)
            {
                PointerExited   += OnPointerExited;
                PointerEntered  += OnPointerEntered;
                PointerCanceled += OnPointerCanceled;
                PointerPressed  += OnPointerPressed;
                PointerReleased += OnPointerReleased;

                _touchSubscription.Disposable = Disposable.Create(() =>
                {
                    PointerExited   -= OnPointerExited;
                    PointerEntered  -= OnPointerEntered;
                    PointerCanceled -= OnPointerCanceled;
                    PointerPressed  -= OnPointerPressed;
                    PointerReleased -= OnPointerReleased;
                });
            }
            else
            {
                if (this.Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug))
                {
                    this.Log().WarnFormat("ControlTemplateRoot is not available, {0} will not be clickable", this.GetType());
                }
            }
        }
예제 #7
0
        public static void SetRowSpan(View view, int rowSpan)
        {
            if (rowSpan <= 0)
            {
                throw new ArgumentException("The value must be above zero", nameof(rowSpan));
            }

            DependencyObjectExtensions.SetValue(view, RowSpanProperty, rowSpan);
        }
예제 #8
0
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            codeEditor = DependencyObjectExtensions.CheckTemplatePart <SimpleCodeTextEditor>(GetTemplateChild("PART_CodeEditor"));

            // Setup again the code editor with new parameters
            SetupCodeEditor();
        }
예제 #9
0
        /// <inheritdoc/>
        /// <inheritdoc />
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            scroller = DependencyObjectExtensions.CheckTemplatePart <ScrollViewer>(GetTemplateChild(ScrollViewerPartName));
            if (scroller != null)
            {
                scroller.ScrollChanged += ScrollChanged;
            }
        }
예제 #10
0
        partial void RegisterEvents()
        {
            _touchSubscription.Disposable     = null;
            _isEnabledSubscription.Disposable = null;

            View uiControl = GetUIControl();

            var nativeButton = uiControl as Android.Widget.Button;

            if (nativeButton is Android.Widget.Button)
            {
                this.Log().Debug("Template contains Android.Widget.Button, hooking up to Click and syncing IsEnabled state");

                _touchSubscription.Disposable = uiControl
                                                .RegisterClick((e, s) =>
                {
                    if (this.Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug))
                    {
                        this.Log().Debug("TouchUpInside, executing command");
                    }

                    // TODO: Simulate the complete pointer sequence on "this", and remove the Tapped and Click
                    // uiControl.SetOnTouchListener()
                    OnPointerPressed(new PointerRoutedEventArgs(this));

                    OnClick();

                    var args = new TappedRoutedEventArgs {
                        OriginalSource = this
                    };

                    RaiseEvent(TappedEvent, args);
                });

                _isEnabledSubscription.Disposable =
                    DependencyObjectExtensions.RegisterDisposablePropertyChangedCallback(
                        this,
                        IsEnabledProperty,
                        (s, e) => uiControl.Enabled = IsEnabled
                        );

                uiControl.Enabled = IsEnabled;
            }
            else if (uiControl != null)
            {
            }
            else
            {
                if (this.Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug))
                {
                    this.Log().WarnFormat("ControlTemplateRoot is not available, {0} will not be clickable", this.GetType());
                }
            }
        }
예제 #11
0
 /// <summary>
 /// Registers to all the attached properties on the children, so that
 /// the control is invalidated when their value changes.
 /// </summary>
 /// <param name="child"></param>
 private void CreateGridChildPropertiesSubscription(NativeView child)
 {
     if (!_childSubscriptions.ContainsKey(child))
     {
         // The tradeoff made here is to assume that registering to all property changes, and checking for DP
         // equality in the callback is less expensive that forcing the initialization of the four grid attached properties
         // storage on all the children.
         _childSubscriptions[child] =
             DependencyObjectExtensions
             .RegisterDisposablePropertyChangedCallback(child, OnChildGridPropertyChanged);
     }
 }
예제 #12
0
        private static dynamic _algorithm; // TODO: this is ugly, better make an Algorithm class or interface

        // check if the player or the computer hit a rectangle containing a ship and return true or false
        public static void CheckHit(Rectangle rect, out bool hasHit, bool fromAi = false)
        {
            // this is a check to make sure the player has placed all of his ships before starting to sink enemy ships
            if (SavedSettings.AgainstCom && PlayerModel.ShipList.Any(s => s.ShipRectangle.Count == 0))
            {
                ChangeErrorText(rect);
                hasHit = false;
                return;
            }

            // we abuse the name property of rectangles as the shipname. NoShip means it's water, everything else is a hit
            if (rect.Name != "NoShip")
            {
                rect.Fill      = new SolidColorBrush(Color.FromRgb(255, 0, 0));
                rect.IsEnabled = false;
                hasHit         = true;
            }
            else
            {
                rect.IsEnabled = false;
                rect.Fill      = new SolidColorBrush(Color.FromRgb(0, 0, 225));
                hasHit         = false;
            }

            // if it was a hit, update the model to make sure the ship loses in length
            if (hasHit)
            {
                var model = fromAi ? PlayerModel : _comModel;
                GetAndUpdateHitShip(rect.Uid, model);
            }

            // if turn counting is enabled, count the turns and update them
            CountTurns();
            if (SavedSettings.ShowTurns)
            {
                UpdateCounter(DependencyObjectExtensions.GetParent <Window>(rect));
            }

            // if either the com or the player has no remaining ships, the game must be over
            if (_comModel.ShipList.Count == 0 || PlayerModel.ShipList.Count == 0)
            {
                var window = DependencyObjectExtensions.GetParent <Window>(rect);
                CallGameOverWindow(window);
                return;
            }

            // after the player clicked a field, let the algorithm try its best
            if (SavedSettings.AgainstCom && !fromAi)
            {
                CombinedAlgorithm();
            }
        }
예제 #13
0
        /// <inheritdoc/>
        public override void OnApplyTemplate()
        {
            templateApplied = false;
            base.OnApplyTemplate();

            if (colorPickerRenderSurface != null)
            {
                colorPickerRenderSurface.MouseDown -= OnColorPickerRenderSurfaceMouseDown;
                colorPickerRenderSurface.MouseUp   -= OnColorPickerRenderSurfaceMouseUp;
                colorPickerRenderSurface.MouseMove -= OnColorPickerRenderSurfaceMouseMove;
            }

            if (huePickerRenderSurface != null)
            {
                huePickerRenderSurface.MouseDown -= OnHuePickerRenderSurfaceMouseDown;
                huePickerRenderSurface.MouseUp   -= OnHuePickerRenderSurfaceMouseUp;
                huePickerRenderSurface.MouseMove -= OnHuePickerRenderSurfaceMouseMove;
            }

            colorPickerRenderSurface  = DependencyObjectExtensions.CheckTemplatePart <Rectangle>(GetTemplateChild("PART_ColorPickerRenderSurface"));
            colorPreviewRenderSurface = DependencyObjectExtensions.CheckTemplatePart <Rectangle>(GetTemplateChild("PART_ColorPreviewRenderSurface"));
            colorPickerSelector       = DependencyObjectExtensions.CheckTemplatePart <Canvas>(GetTemplateChild("PART_ColorPickerSelector"));
            huePickerSelector         = DependencyObjectExtensions.CheckTemplatePart <Rectangle>(GetTemplateChild("PART_HuePickerSelector"));
            huePickerRenderSurface    = DependencyObjectExtensions.CheckTemplatePart <FrameworkElement>(GetTemplateChild("PART_HuePickerRenderSurface"));

            if (colorPickerRenderSurface != null)
            {
                colorPickerRenderSurface.MouseDown += OnColorPickerRenderSurfaceMouseDown;
                colorPickerRenderSurface.MouseUp   += OnColorPickerRenderSurfaceMouseUp;
                colorPickerRenderSurface.MouseMove += OnColorPickerRenderSurfaceMouseMove;
            }

            if (huePickerRenderSurface != null)
            {
                huePickerRenderSurface.MouseDown += OnHuePickerRenderSurfaceMouseDown;
                huePickerRenderSurface.MouseUp   += OnHuePickerRenderSurfaceMouseUp;
                huePickerRenderSurface.MouseMove += OnHuePickerRenderSurfaceMouseMove;
            }

            RenderColorPickerSurface();

            if (colorPickerSelector != null && colorPickerRenderSurface != null)
            {
                Canvas.SetLeft(colorPickerSelector, Saturation * colorPickerRenderSurface.Width / 100.0);
                Canvas.SetTop(colorPickerSelector, Brightness * colorPickerRenderSurface.Height / 100.0);
            }
            if (huePickerSelector != null && huePickerRenderSurface != null)
            {
                Canvas.SetLeft(huePickerSelector, Hue * huePickerRenderSurface.Width / 360.0);
            }
            templateApplied = true;
        }
예제 #14
0
        public BinderDetails(DependencyObject owner)
        {
            this._store = ((IDependencyObjectStoreProvider)owner).Store;
            this._owner = owner;

            _store.RegisterPropertyChangedCallback(_store.DataContextProperty, Binder_DataContextChanged);
            _store.RegisterPropertyChangedCallback(_store.TemplatedParentProperty, Binder_TemplatedParentChanged);

            _props = DependencyProperty.GetPropertiesForType(owner.GetType());

            DependencyObjectExtensions
            .RegisterDisposablePropertyChangedCallback(_owner, (instance, p, e) => UpdateProperties());
        }
        void AssociatedObjectLoaded(object sender, RoutedEventArgs e)
        {
            AssociatedObject.Loaded -= AssociatedObjectLoaded;

            _treeviewScrollViewer = DependencyObjectExtensions.GetChildByType(AssociatedObject, typeof(ScrollViewer)) as ScrollViewer;

            //Juries - Removed, instead implement a collection changed handler, to only scroll to end when new items are added.
            if (_treeviewScrollViewer != null)
            {
                _treeviewScrollViewer.IsDeferredScrollingEnabled = true;
                _treeviewScrollViewer.PreviewMouseDown          += (o, args) => _hasUserScrolled = true;
                _treeviewScrollViewer.ScrollChanged += TreeviewScrollViewerScrollChanged;
            }
        }
예제 #16
0
 protected override void OnItemsSourceChanged(OldNew <IEnumerable> input)
 {
     base.OnItemsSourceChanged(input);
     if (TreeViewExtensions.GetMode(treeView) == TreeViewModes.Grid)
     {
         var columns = TreeViewExtensions.GetColumns(treeView);
         if (columns?.Count > 0)
         {
             columns.ForEach(i =>
             {
                 if (!DependencyObjectExtensions.GetIsVisible(i))
                 {
                     Hide(i);
                 }
             });
         }
     }
 }
예제 #17
0
        public void FrameworkElementExtensions_ArgumentChecks()
        {
            var element = new Button();

            AssertEx.Throws <ArgumentNullException>(
                () => DependencyObjectExtensions.SetTag(null, 0),
                ex => Assert.AreEqual("view", ex.ParamName));

            AssertEx.Throws <ArgumentNullException>(
                () => DependencyObjectExtensions.SetReactContext(null, null),
                ex => Assert.AreEqual("view", ex.ParamName));

            AssertEx.Throws <ArgumentNullException>(
                () => DependencyObjectExtensions.GetTag(null),
                ex => Assert.AreEqual("view", ex.ParamName));

            AssertEx.Throws <ArgumentNullException>(
                () => DependencyObjectExtensions.GetReactContext(null),
                ex => Assert.AreEqual("view", ex.ParamName));
        }
        public void FrameworkElementExtensions_ArgumentChecks()
        {
            ArgumentNullException ex1 = Assert.Throws <ArgumentNullException>(
                () => DependencyObjectExtensions.SetTag(null, 0));

            Assert.AreEqual("view", ex1.ParamName);

            ArgumentNullException ex2 = Assert.Throws <ArgumentNullException>(
                () => DependencyObjectExtensions.SetReactContext(null, null));

            Assert.AreEqual("view", ex2.ParamName);

            ArgumentNullException ex3 = Assert.Throws <ArgumentNullException>(
                () => DependencyObjectExtensions.GetTag(null));

            Assert.AreEqual("view", ex3.ParamName);

            ArgumentNullException ex4 = Assert.Throws <ArgumentNullException>(
                () => DependencyObjectExtensions.GetReactContext(null));

            Assert.AreEqual("view", ex4.ParamName);
        }
        private async static void ItemsSourceChanged(object sender, EventArgs eventArgs)
        {
            var itemsControl = (ItemsControl)sender;

            if (itemsControl.ItemsSource == null)
            {
                return;
            }

            var opacityAnimation = new DoubleAnimation(0, 1, TimeSpan.FromMilliseconds(260), FillBehavior.Stop);
            var marginAnimation  = new ThicknessAnimation(new Thickness(-20, 0, 20, 0), new Thickness(0),
                                                          TimeSpan.FromMilliseconds(240), FillBehavior.Stop)
            {
                EasingFunction = new CircleEase {
                    EasingMode = EasingMode.EaseOut
                }
            };

            if (Timers.ContainsKey(itemsControl))
            {
                Timers[itemsControl].Stop();
                Timers.Remove(itemsControl);
            }

            List <ListBoxItem> visibleItems;

            itemsControl.Opacity = 0;
            while (true)
            {
                visibleItems = DependencyObjectExtensions.GetVisibleItemsFromItemsControl(itemsControl,
                                                                                          Window.GetWindow(itemsControl));
                if (visibleItems.Count > 0 || itemsControl.Items.Count == 0)
                {
                    break;
                }
                await Task.Delay(1);
            }
            Debug.Print("Items to animate: " + visibleItems.Count);
            foreach (var item in visibleItems)
            {
                item.Opacity = 0;
            }
            itemsControl.Opacity = 1;
            DispatcherTimer dispatcherTimer;

            var enumerator = visibleItems.GetEnumerator();

            if (enumerator.MoveNext())
            {
                ScrollChangedEventHandler scrollChangedEventHandler = null;
                scrollChangedEventHandler = (o, args) =>
                {
                    var handler = scrollChangedEventHandler;

                    if (handler != null)
                    {
                        itemsControl.RemoveHandler(ScrollViewer.ScrollChangedEvent, handler);
                    }

                    if (!Timers.ContainsKey(itemsControl) || !Timers[itemsControl].IsEnabled)
                    {
                        return;
                    }

                    var timer = Timers[itemsControl];
                    timer.Stop();

                    while (true)
                    {
                        var item = enumerator.Current;
                        if (item == null)
                        {
                            break;
                        }
                        item.Opacity = 1;
                        if (!enumerator.MoveNext())
                        {
                            break;
                        }
                    }
                };

                dispatcherTimer = new DispatcherTimer {
                    Interval = TimeSpan.FromMilliseconds(30)
                };
                dispatcherTimer.Tick += (s, timerE) =>
                {
                    var item = enumerator.Current;
                    if (item == null)
                    {
                        return;
                    }
                    item.BeginAnimation(FrameworkElement.MarginProperty, marginAnimation);
                    item.BeginAnimation(UIElement.OpacityProperty, opacityAnimation);
                    item.Opacity = 1;
                    if (!enumerator.MoveNext())
                    {
                        dispatcherTimer.Stop();
                        itemsControl.RemoveHandler(ScrollViewer.ScrollChangedEvent, scrollChangedEventHandler);
                    }
                };

                if (Timers.ContainsKey(itemsControl))
                {
                    Timers.Remove(itemsControl);
                }
                Timers.Add(itemsControl, dispatcherTimer);
                dispatcherTimer.Start();

                itemsControl.AddHandler(ScrollViewer.ScrollChangedEvent, scrollChangedEventHandler);
            }
        }
 public static void SetMyValue(object view, int row)
 {
     DependencyObjectExtensions.SetValue(view, MyValueProperty, row);
 }
 public static int GetMyValue(object view)
 {
     return((int)DependencyObjectExtensions.GetValue(view, MyValueProperty));
 }
예제 #22
0
 public static void SetColumn(View view, int column)
 {
     DependencyObjectExtensions.SetValue(view, ColumnProperty, column);
 }
 public static IEnumerable <Paragraph> Paragraphs(FlowDocument doc)
 {
     return(DependencyObjectExtensions.Descendants(doc).OfType <Paragraph>());
 }
예제 #24
0
        public static BitmapSource OverlayInk(BitmapSource bitmapSource, double scale, StrokeCollection inkStrokes)
        {
            if (bitmapSource == null)
            {
                return((BitmapSource)null);
            }
            if (inkStrokes == null || inkStrokes.Count == 0)
            {
                return(bitmapSource);
            }
            Rect   rect1        = new Rect(0.0, 0.0, (double)bitmapSource.PixelWidth, (double)bitmapSource.PixelHeight);
            Vector offsetVector = (Vector)RectExtensions.GetCenter(rect1);
            Rect   rect2        = RectExtensions.Union(Enumerable.Select <Stroke, Rect>((IEnumerable <Stroke>)inkStrokes, (Func <Stroke, Rect>)(stroke => stroke.GetBounds())));

            rect2.Scale(scale, scale);
            rect2.Offset(offsetVector);
            Rect   rect3   = Rect.Union(rect1, rect2);
            Canvas canvas1 = new Canvas();

            canvas1.Width  = rect3.Width;
            canvas1.Height = rect3.Height;
            canvas1.Children.Add((UIElement) new Image()
            {
                Source = (ImageSource)bitmapSource
            });
            UIElementCollection children      = canvas1.Children;
            InkPresenter        inkPresenter1 = new InkPresenter();

            inkPresenter1.Strokes         = inkStrokes;
            inkPresenter1.Margin          = new Thickness(offsetVector.X, offsetVector.Y, -offsetVector.X, -offsetVector.Y);
            inkPresenter1.LayoutTransform = (Transform) new ScaleTransform(scale, scale);
            InkPresenter inkPresenter2 = inkPresenter1;

            children.Add((UIElement)inkPresenter2);
            Canvas canvas2   = canvas1;
            Point  newOrigin = new Point(-rect3.Left, -rect3.Top);

            EnumerableExtensions.ForEach <UIElement>(Enumerable.OfType <UIElement>((IEnumerable)canvas2.Children), (Action <UIElement>)(child => DependencyObjectExtensions.SetCanvasPos((DependencyObject)child, newOrigin)));
            return(new FrameworkElementCapturer((FrameworkElement)canvas2, ImageCapturer.MaxSize).Capture());
        }
예제 #25
0
 public static void SetMyExplicitValue(Target1 view, int row)
 {
     DependencyObjectExtensions.SetValue(view, MyValueProperty, row);
 }
예제 #26
0
 public static void SetRow(View view, int row)
 {
     DependencyObjectExtensions.SetValue(view, RowProperty, row);
 }
예제 #27
0
 public static AttachedDependencyObject GetDependencyObjectForXBind(this object instance)
 => DependencyObjectExtensions.GetAttachedDependencyObject(instance);
예제 #28
0
 public static int GetRowSpan(View view)
 {
     return((int)DependencyObjectExtensions.GetValue(view, RowSpanProperty));
 }