Inheritance: UIElement, IFrameworkInputElement, IInputElement, ISupportInitialize, IHaveResources, IQueryAmbient
        internal void AddAdorner(
            AdornerLayer treeViewAdornerLayer, FrameworkElement adornedElement, ExplorerEFElement explorerElement,
            ExplorerFrame explorerFrame)
        {
            var adornerY = GetAdornerY(adornedElement, explorerElement, explorerFrame);

            if (adornerY >= 0)
            {
                SearchTickAdorner adorner;
                if (!_adorners.TryGetValue(adornerY, out adorner))
                {
                    adorner = new SearchTickAdorner(adornerY, adornedElement);
                    _adorners[adornerY] = adorner;
                    treeViewAdornerLayer.Add(adorner);

                    // adding adorners in batches of 100 - see bug: Windows OS Bugs 1750717 
                    if ((_adorners.Count % 100) == 0)
                    {
                        treeViewAdornerLayer.UpdateLayout();
                    }
                }

                adorner.AddExplorerElement(explorerElement);
            }
        }
 public void ShowChildWindow(FrameworkElement content)
 {
     XmlContent = content;
     OnPropertyChanged("XmlContent");
     WindowVisibility = Visibility.Visible;
     OnPropertyChanged("WindowVisibility");
 }
Example #3
1
 public UIAdorner(FrameworkElement adornee, FrameworkElement content)
     : base(adornee)
 {
     this.adornee = adornee;
     this.content = content;
     AddVisualChild(this.content);
 }
        public void OnLoaded(object sender, EventArgs e)
        {
            // Enable moving the window when clicking on the control CtlMoveable 
            this.CtlMoveable = (FrameworkElement)this.Template.FindName("CtlMoveable", this);
            if (null != this.CtlMoveable)
            {
                this.CtlMoveable.MouseLeftButtonDown += new MouseButtonEventHandler(OnMoveableClick);
            }

            Application.Current.MainWindow = this;

            // Disable Minimize and close buttons
            var BtnClose = (FrameworkElement)this.Template.FindName("BtnClose", this);
            if (BtnClose != null)
                BtnClose.Visibility = System.Windows.Visibility.Hidden;

            var BtnMinimize = (FrameworkElement)this.Template.FindName("BtnMinimize", this);
            if (BtnMinimize != null)
                BtnMinimize.Visibility = System.Windows.Visibility.Hidden;

            // Check for updates async
            // and register an event to catch its answer
            vm.LoadApplicationData();
            vm.SelfUpdaterApp.PropertyChanged += vm_PropertyChanged;
            vm.UpdateSelfUpdaterAsync();
            CtlProgress.Maximum = 1;
        }
Example #5
1
        public static void SetUpdateBindingOnChange(FrameworkElement element, bool value)
        {
            Action<TextBox, bool> action = (txtBox, updateValue) =>
            {
                if (GetUpdateBindingOnChange(txtBox) == updateValue) return;

                if (updateValue)
                {
                    txtBox.TextChanged += element_TextChanged;
                }
                else
                {
                    txtBox.TextChanged -= element_TextChanged;
                }

                txtBox.SetValue(UpdateBindingOnChangeProperty, updateValue);
            };

            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                if (element is TextBox)
                {
                    action.Invoke(element as TextBox, value);
                    return;
                }

                element.GetChildrens<TextBox>().ForEach(i => action.Invoke(i, value));
            });
        }
Example #6
1
 public void Detach(FrameworkElement element)
 {
     element.MouseMove -= MouseMoveHandler;
     element.MouseRightButtonDown -= MouseDownHandler;
     element.MouseRightButtonUp -= MouseUpHandler;
     element.MouseWheel -= OnMouseWheel;
 }
        public static bool StateWellDefined(FrameworkElement element, string stateName, bool prefixControlName = false)
        {
            string state = string.IsNullOrWhiteSpace(stateName) ? null : (prefixControlName ? element.Name + "_" + 
                stateName : stateName);

            // Look for the visual state on the first child object.  This is generally where states are declared
            // when they are part of a ControlTemplate.
            FrameworkElement child = null;
            if (VisualTreeHelper.GetChildrenCount(element) > 0)
                child = VisualTreeHelper.GetChild(element, 0) as FrameworkElement;

            if (child == null)
                return false;

            var vsgs = VisualStateManager.GetVisualStateGroups(child);
            if (vsgs != null && vsgs.Count > 0)
            {
                foreach (VisualStateGroup vsg in vsgs)
                {
                    if (vsg.States != null)
                    {
                        foreach (VisualState vs in vsg.States)
                        {
                            if (vs.Name == state)
                                return true;
                        }
                    }
                }
            }
            return false;
        }
Example #8
1
 /// <summary>
 /// Return wheter the mouse is over a control
 /// </summary>
 /// <param name="s"></param>
 /// <param name="e"></param>
 /// <returns>True if the mouse is over a control, false otherwise</returns>
 internal static bool IsMouseOver(FrameworkElement s, System.Windows.Input.MouseEventArgs e)
 {
     Rect bounds = new Rect(0, 0, s.ActualWidth, s.ActualHeight);
     if (bounds.Contains(e.GetPosition(s)))
         return true;
     return false;
 }
Example #9
1
        public void SetupTargetBinding(FrameworkElement targetObject)
        {
            if (targetObject == null)
            {
                return;
            }

            // Prevent the designer from reporting exceptions since
            // changes will be made of a Binding in use if it is set
            if (DesignerProperties.GetIsInDesignMode(this) == true)
                return;

            // Bind to the selected TargetProperty, e.g. ActualHeight and get
            // notified about changes in OnTargetPropertyListenerChanged
            var listenerBinding = new Binding
            {
                Source = targetObject,
                Path = new PropertyPath(TargetProperty),
                Mode = BindingMode.OneWay
            };
            BindingOperations.SetBinding(this, TargetPropertyListenerProperty, listenerBinding);

            // Set up a OneWayToSource Binding with the Binding declared in Xaml from
            // the Mirror property of this class. The mirror property will be updated
            // everytime the Listener property gets updated
            BindingOperations.SetBinding(this, TargetPropertyMirrorProperty, Binding);
            TargetPropertyValueChanged();
        }
        public static Border CreateBlockBox(FrameworkElement child, double width, double height, double x, double y, Color backgroundColor)
        {
            var border = new Border()
            {
                BorderThickness = new Thickness(1, 1, 1, 1),
                BorderBrush = Brushes.Silver,
                Background = new SolidColorBrush(backgroundColor),

                Width = width,
                Height = height,
                Margin = new Thickness(x, y, 0, 0),
                Child = child
            };

            border.MouseEnter += (s, e) =>
            {
                border.Width = Math.Max(width, child.ActualWidth);
                border.Height = Math.Max(height, child.ActualHeight);
                Panel parent = (Panel)border.Parent;
                border.TopMost();
            };

            border.MouseLeave += (s, e) =>
            {
                border.Width = width;
                border.Height = height;
            };

            return border;
        }
        public void CloseExists()
        {
            CreateContainerWithRealMessageBus();

            var title = Guid.NewGuid().ToString();

            var viewModel = Substitute.For<ITitledViewModel>();
            viewModel.Title.Returns(title);

            var view = new FrameworkElement();
            view.DataContext = viewModel;
            var viewTarget = ViewTargets.DefaultView;

            var viewResult = new ViewResult(view, viewTarget);
            var viewBuilder = Substitute.For<IViewFactory>();
            viewBuilder.Build(Arg.Any<ViewTargets>(), Arg.Any<Object>())
                .Returns(viewResult);
            ComponentContainer.Container.Register(Component.For<IViewFactory>().Instance(viewBuilder));

            var window = new Window();
            var tabControl = new TabControl();
            var viewController = new ViewPlacer(window, tabControl);
            var newTabItem = new TabItem() { Header = title };
            tabControl.Items.Add(newTabItem);

            var message = new CloseViewMessage(title);
            _MessageBus.Publish<CloseViewMessage>(message);

            Assert.AreEqual(0, tabControl.Items.Count);
        }
        protected override FrameworkElement ModifyNewContent(ITransitionControl container, FrameworkElement newContent)
        {
            if (newContent == null)
            {
                HideBackground(container);
                container.Remove(_border);
                return null;
            }

            ShowBackground(container);

            _border = WrapInBorder(newContent);

            _border.Opacity = 0;

            SetPosition(_border);

            newContent.SizeChanged += (sender, e) => SetPosition(_border);

            var ctrl = container.AsControl();

            ctrl.SizeChanged += (sender, e) => SetPosition(_border);

            return _border;
        }
        public static void Bind(FrameworkElement view, object viewModel)
        {
            Log.Info($"Binding '{view}' to '{viewModel}'");

            var namedElements = UIHelper.FindNamedChildren(view);

            var viewModelProperties = viewModel.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);

            var matches = namedElements.Join(viewModelProperties, e => e.Name, p => p.Name, (e, p) => new { e, p });

            foreach (var element in namedElements)
            {
                var matchingProperty = viewModelProperties.Where(p => p.Name == element.Name).SingleOrDefault();
                if (matchingProperty == null)
                {
                    Log.Debug($"No matching property for element '{element.Name}'");
                    continue;
                }

                if (!TryBind(element, matchingProperty, viewModel))
                    Log.Debug($"Could not bind element '{element.Name}' to property '{matchingProperty.Name}'");
            }

            view.DataContext = viewModel;

            var viewAware = viewModel as IViewAware;
            viewAware?.AttachView(view);
        }
 public void CloseChildWindow()
 {
     WindowVisibility = Visibility.Collapsed;
     OnPropertyChanged("WindowVisibility");
     XmlContent = null;
     OnPropertyChanged("XmlContent");
 }
 public void Show(FrameworkElement popupContent)
 {
     _PopupContent = popupContent;
     _Popup = new Popup();
     _Popup.Child = this;
     _Popup.IsOpen = true;
 }
Example #16
0
 public static void VoteVisible(FrameworkElement fe)
 {
     foreach (var item in fe.LogicalParents().TakeWhile(a => GetAutoHide(a) != AutoHide.Visible))
     {
         SetAutoHide(item, AutoHide.Visible);
     }
 }
Example #17
0
 public void Attach(FrameworkElement element)
 {
     element.MouseMove += MouseMoveHandler;
     element.MouseRightButtonDown += MouseDownHandler;
     element.MouseRightButtonUp += MouseUpHandler;
     element.MouseWheel += OnMouseWheel;
 }
Example #18
0
 public static void VoteCollapsed(FrameworkElement fe)
 {
     foreach (var item in fe.LogicalParents().TakeWhile(a => GetAutoHide(a) == AutoHide.Undefined))
     {
         SetAutoHide(item, AutoHide.Collapsed);
     }
 }
Example #19
0
 public void Open(FrameworkElement container)
 {
     if (container != null)
     {
         _container = container;
         // 通过禁用来模拟模态的对话框
         _container.IsEnabled = false;
         // 保持总在最上
         this.Owner = GetOwnerWindow(container);
         if (this.Owner != null)
         {
             this.Owner.Closing += new System.ComponentModel.CancelEventHandler(Owner_Closing);
         }
         // 通过监听容器的Loaded和Unloaded来显示/隐藏窗口
         _container.Loaded += new RoutedEventHandler(Container_Loaded);
         _container.Unloaded += new RoutedEventHandler(Container_Unloaded);
     }
     this.Show();
     try
     {
         ComponentDispatcher.PushModal();
         _dispatcherFrame = new DispatcherFrame(true);
         Dispatcher.PushFrame(_dispatcherFrame);
     }
     finally
     {
         ComponentDispatcher.PopModal();
     }
 }
        /// <summary>
        /// Replaces the content for a <see cref="DataField"/> with another control and updates the bindings.
        /// </summary>
        /// <param name="field">The <see cref="DataField"/> whose <see cref="TextBox"/> will be replaced.</param>
        /// <param name="newControl">The new control you're going to set as <see cref="DataField.Content" />.</param>
        /// <param name="dataBindingProperty">The control's property that will be used for data binding.</param>        
        /// <param name="bindingSetupFunction">
        ///  An optional <see cref="Action"/> you can use to change parameters on the newly generated binding before
        ///  it is applied to <paramref name="newControl"/>
        /// </param>
        /// <param name="sourceProperty">The source dependency property to use for the binding.</param>
        public static void ReplaceContent(this DataField field, FrameworkElement newControl, DependencyProperty dataBindingProperty, Action<Binding> bindingSetupFunction, DependencyProperty sourceProperty)
        {
            if (field == null)
            {
                throw new ArgumentNullException("field");
            }

            if (newControl == null)
            {
                throw new ArgumentNullException("newControl");
            }

            // Construct new binding by copying existing one, and sending it to bindingSetupFunction
            // for any changes the caller wants to perform
            Binding newBinding = field.Content.GetBindingExpression(sourceProperty).ParentBinding.CreateCopy();

            if (bindingSetupFunction != null)
            {
                bindingSetupFunction(newBinding);
            }

            // Replace field
            newControl.SetBinding(dataBindingProperty, newBinding);
            field.Content = newControl;
        }
        public static void CreateIcon(FrameworkElement element, int width, int height, string path)
        {
            try
            {
                RenderTargetBitmap bmp = new RenderTargetBitmap(width, height, 96, 96, PixelFormats.Pbgra32);
                bmp.Render(element);

                string file = path;

                string Extension = Path.GetExtension(file).ToLower();

                BitmapEncoder encoder;
                if (Extension == ".gif")
                    encoder = new GifBitmapEncoder();
                else if (Extension == ".png")
                    encoder = new PngBitmapEncoder();
                else if (Extension == ".jpg")
                    encoder = new JpegBitmapEncoder();
                else
                    return;

                encoder.Frames.Add(BitmapFrame.Create(bmp));

                using (Stream stm = File.Create(file))
                {
                    encoder.Save(stm);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Example #22
0
        public static void ExecuteOnLoaded(FrameworkElement fe, Action action)
        {
            if (fe.IsLoaded)
            {
                if (action != null)
                {
                    action();
                }
            }
            else
            {
                RoutedEventHandler handler = null;
                handler = delegate
                {
                    fe.Loaded -= handler;

                    if (action != null)
                    {
                        action();
                    }
                };

                fe.Loaded += handler;
            }
        }
Example #23
0
        public static void SetSelectAllOnFocus(FrameworkElement element, bool value)
        {
            Action<TextBox, bool> action = (textBox, value1) =>
            {
                if (GetSelectAllOnFocus(textBox) == value1) return;

                if (value1)
                {
                    textBox.GotFocus += element_GotFocus;
                }
                else
                {
                    textBox.GotFocus -= element_GotFocus;
                }

                textBox.SetValue(SelectAllOnFocusProperty, value1);
            };

            Deployment.Current.Dispatcher.BeginInvoke(() => {
                if (element is TextBox)
                {
                    action.Invoke(element as TextBox, value);
                }
                else
                {
                    element.GetChildrens<TextBox>().ForEach(i => action.Invoke(i, value));
                }
            });
        }
Example #24
0
 public static void OnClick(FrameworkElement element, Action action, params FrameworkElement[] exclusions)
 {
     ClickEvent c = new ClickEvent(action, mainGrid, exclusions);
     element.MouseLeftButtonDown += c.OnButtonDown;
     element.MouseLeftButtonUp += c.OnButtonUp;
     list.Add(c);
 }
Example #25
0
        public void ShowControl(FrameworkElement control)
        {
            Initialize(new Window());

            this.Window.Content = control;
            ShowWindow();
        }
        public MouseWheelSupport(FrameworkElement elementToAddMouseWheelSupportTo, FrameworkElement parentElementWithMouseWheelSupport)
        {
            ElementToAddMouseWheelSupportTo = elementToAddMouseWheelSupportTo;

            //Make sure the browser listener is setup
            if (browserListener == null)
                browserListener = new BrowserMouseWheelEventListener();

            //Add an event handler to the browser listener for this particular Silverlight element
            browserListener.Moved += this.HandleBrowserMouseWheelMoved;
            
            //Setup the focus/blur handlers for the Silverlight element
            elementToAddMouseWheelSupportTo.GotFocus += new RoutedEventHandler(ElementGotFocus);
            elementToAddMouseWheelSupportTo.LostFocus += new RoutedEventHandler(ElementLostFocus);

            //Setup mouse move for the Silverlight element
            elementToAddMouseWheelSupportTo.MouseMove += new System.Windows.Input.MouseEventHandler(ElementMouseMove);

            elementToAddMouseWheelSupportTo.MouseEnter += new System.Windows.Input.MouseEventHandler(elementToAddMouseWheelSupportTo_MouseEnter);
            elementToAddMouseWheelSupportTo.MouseLeave += new System.Windows.Input.MouseEventHandler(elementToAddMouseWheelSupportTo_MouseLeave);
            elementToAddMouseWheelSupportTo.LostMouseCapture += new System.Windows.Input.MouseEventHandler(elementToAddMouseWheelSupportTo_LostMouseCapture);

            //Add a new node to our tree and save a reference to the node for this element
            elementState = elementStateTree.Add(elementToAddMouseWheelSupportTo, parentElementWithMouseWheelSupport);
        }
 /// <summary>
 ///     Instantiates a new instance of this class.
 /// </summary>
 /// <param name="column">The column of the cell that is about to exit edit mode.</param>
 /// <param name="row">The row container of the cell container that is about to exit edit mode.</param>
 /// <param name="editingElement">The editing element within the cell.</param>
 /// <param name="editingUnit">The editing unit that is about to leave edit mode.</param>
 public DataGridCellEditEndingEventArgs(DataGridColumn column, DataGridRow row, FrameworkElement editingElement, DataGridEditAction editAction)
 {
     _dataGridColumn = column;
     _dataGridRow = row;
     _editingElement = editingElement;
     _editAction = editAction;
 }
Example #28
0
        /// <summary>
        /// Get the top and bottom of a TreeViewItem with respect to its parent.
        /// </summary>
        /// <param name="item">The item to get the position of.</param>
        /// <param name="parent">The parent of the item.</param>
        /// <param name="top">Vertical offset to the top of the item.</param>
        /// <param name="bottom">
        /// Vertical offset to the bottom of the item.
        /// </param>
        public static void GetTopAndBottom(this TreeViewItem item, FrameworkElement parent, out double top, out double bottom)
        {
            Debug.Assert(item != null, "item should not be null!");
            Debug.Assert(parent != null, "parent should not be null!");

            GetTopAndBottom(item.HeaderElement ?? item, parent, out top, out bottom);
        }
        public IClipboardObject AddAsHtml(FrameworkElement fe, Size imageSize, Size imageElementSize)
        {
            if (fe == null)
                throw new NullReferenceException(nameof(fe));

            var bmp = fe.RenderToBitmap(imageSize);

            var img_src = string.Empty;

            var use_inline_image = false;
            if (use_inline_image)
            {
                // Inline images are not actually supported by Office applications, so don't use it.
                // maybe in future...
                var img_data = bmp.ToBitmap().ToArray();
                var base64_img_data = Convert.ToBase64String(img_data);
                img_src = $"data:image/png;charset=utf-8;base64, {base64_img_data}";
            }
            else
            {
                // create a temp file with image and use it as a source
                var tmp = Path.GetTempFileName();
                bmp.Save(tmp);
                img_src = new Uri(tmp, UriKind.Absolute).ToString();
            }

            var html_data = CF_HTML.PrepareHtmlFragment($"<img height=\"{imageElementSize.Height}\" width=\"{imageElementSize.Width}\" src=\"{img_src}\" />");

            Data.SetData(DataFormats.Html, html_data);

            return this;
        }
        private void MakeDataContextAware(FrameworkElement frameworkElement)
        {
            Contract.Requires<ArgumentNullException>(frameworkElement != null);

            if (frameworkElement.DataContext != null)
                MakeAware(frameworkElement.DataContext);
        }