Пример #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="WindowControlBoxBehavior"/> class.
        /// </summary>
        public WindowControlBoxBehavior()
        {
            h = (s, e) =>
            {
                var isDesign = DesignTimeHelper.GetIsInDesignMode();
                var hWnd     = new WindowInteropHelper(this.AssociatedObject).Handle;

                if (!isDesign && hWnd != IntPtr.Zero && (!this.AllowMaximize || !this.AllowMinimize))
                {
                    var windowLong = NativeMethods.GetWindowLong(hWnd, WindowLong.Style).ToInt32();

                    if (!this.AllowMaximize)
                    {
                        windowLong = windowLong & ~Constants.WS_MAXIMIZEBOX;
                    }

                    if (!this.AllowMinimize)
                    {
                        windowLong = windowLong & ~Constants.WS_MINIMIZEBOX;
                    }

                    NativeMethods.SetWindowLong(hWnd, WindowLong.Style, ( IntPtr )windowLong);
                }
            };
        }
Пример #2
0
        private static void OnSelectedItemsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            if (!DesignTimeHelper.GetIsInDesignMode())
            {
                if (e.OldValue != null)
                {
                    //Probabilmente c'è un handler da sganciare
                    var handler = d.GetValue(selectionHandlerProperty) as SelectionHandler;
                    if (handler != null)
                    {
                        handler.StopSync();
                        d.ClearValue(selectionHandlerProperty);
                    }
                }

                if (e.NewValue != null)
                {
                    //C'è un handler da agganciare
                    var handler = new SelectionHandler();
                    handler.SartSync(d.CastTo <ListView>(), e.NewValue.CastTo <IList>());

                    d.SetValue(selectionHandlerProperty, handler);
                }
            }
        }
        static void OnContentChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var isDesignMode = DesignTimeHelper.GetIsInDesignMode();

            if (!isDesignMode)
            {
                Ensure.That(d.GetType()).Is <ItemsControl>();

                d.CastTo <ItemsControl>().Loaded += onLoaded;
            }
        }
Пример #4
0
 private static void OnCommandChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
 {
     if (!DesignTimeHelper.GetIsInDesignMode())
     {
         var textBox = d as TextBox;
         if (textBox != null)
         {
             textBox.Loaded += onLoaded;
         }
     }
 }
Пример #5
0
        static void OnCueBannerPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var isDesignMode = DesignTimeHelper.GetIsInDesignMode();

            if (!isDesignMode)
            {
                //Ensure.That( sender.GetType() ).Is<TextBoxBase>();

                var control = ( UIElement )sender;
                control.AddHandler(FrameworkElement.LoadedEvent, onLoaded, true);
            }
        }
Пример #6
0
        private static void OnSortCommandChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            if (!DesignTimeHelper.GetIsInDesignMode())
            {
                var listView = Ensure.That(d as ListView)
                               .Named("d")
                               .WithMessage("This behavior can be attached only to ListView(s).")
                               .IsNotNull()
                               .GetValue();

                if (!ListViewManager.GetIsLoadEventAttached(listView))
                {
                    listView.Loaded += onLoaded;
                    ListViewManager.SetIsLoadEventAttached(listView, true);
                }
            }
        }
Пример #7
0
        static void OnContentPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs args)
        {
            if (!DesignTimeHelper.GetIsInDesignMode())
            {
                var control = ( FrameworkElement )d;
                if (!control.IsLoaded)
                {
                    control.Loaded += (s, e) =>
                    {
                        var layer = AdornerLayer.GetAdornerLayer(control);
                        Debug.WriteLineIf(layer == null, "Overlay: cannot find any AdornerLayer on the given element.");

                        if (layer != null)
                        {
                            var content = GetContent(control);
                            if (content != null)
                            {
                                var a = new ContentOverlayAdorner(control, content);
                                layer.Add(a);

                                SetOverlayAdorner(control, a);
                            }
                        }
                    };

                    control.Unloaded += (s, e) =>
                    {
                        var layer = AdornerLayer.GetAdornerLayer(control);
                        Debug.WriteLineIf(layer == null, "Overlay: cannot find any AdornerLayer on the given element.");

                        if (layer != null)
                        {
                            var a = GetOverlayAdorner(control);
                            if (a != null)
                            {
                                layer.Remove(a);

                                SetOverlayAdorner(control, null);
                            }
                        }
                    };
                }
            }
        }
Пример #8
0
        private static void OnChanged(DependencyObject owner, DependencyPropertyChangedEventArgs e)
        {
            var isLoadedAttached = GetOnLoadedAttached(owner);

            if (!isLoadedAttached && !DesignTimeHelper.GetIsInDesignMode())
            {
                var fe = owner as FrameworkElement;
                if (fe != null)
                {
                    fe.Loaded += OnLoaded;
                }
                var fce = owner as FrameworkContentElement;
                if (fce != null)
                {
                    fce.Loaded += OnLoaded;
                }
                SetOnLoadedAttached(owner, true);
            }
        }
Пример #9
0
        private static void OnItemRemoveCommandChanged(DependencyObject target, DependencyPropertyChangedEventArgs e)
        {
            if (!DesignTimeHelper.GetIsInDesignMode())
            {
                Ensure.That(target.GetType())
                .WithMessage("This behavior can be attached to ListView(s) only.")
                .Is <ListView>();

                var lv = ( ListView )target;
                if ((e.NewValue != null) && (e.OldValue == null))
                {
                    lv.KeyDown += onKeyDown;
                }
                else if ((e.NewValue == null) && (e.OldValue != null))
                {
                    lv.KeyDown -= onKeyDown;
                }
            }
        }
Пример #10
0
 static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
 {
     if (!DesignTimeHelper.GetIsInDesignMode())
     {
         var control = ( FrameworkElement )d;
         if (!control.IsLoaded && !Gethandled(control))
         {
             control.Loaded += (s, rea) => HandleStatusChanged(control);
             Sethandled(control, true);
         }
         else if (control.IsLoaded && e.Property == StatusProperty)
         {
             HandleStatusChanged(control);
         }
         else if (control.IsLoaded && e.Property == ContentProperty)
         {
             HandleContentChanged(control);
         }
     }
 }