Ejemplo n.º 1
0
 private bool IsSubClassOf(UIElement ui, Type type)
 {
     while (null != ui)
     {
         if ((ui.GetType() == type) ||
             (ui.GetType().IsSubclassOf(type)))
         {
             return true;
         }
         ui = VisualTreeHelper.GetParent(ui) as UIElement;
     }
     return false;
 }
Ejemplo n.º 2
0
        public static IntPtr GetThumbnail(IntPtr hWnd, System.Windows.UIElement targetElement)
        {
            Debug.WriteLine($"{hWnd} {targetElement}");
            DwmRegisterThumbnail(new WindowInteropHelper(Window.GetWindow(targetElement)).Handle, hWnd, out var thumbHandle);
            var   targetElementPoint = MainTools.GetDpiScaledGlobalControlPosition(targetElement);
            Point targetElementOppositePoint;

            if (targetElement.GetType().IsAssignableFrom(typeof(System.Windows.Controls.Control)))
            {
                var targetControl = (targetElement as System.Windows.Controls.Control);
                targetElementOppositePoint = new Point(targetElementPoint.X + targetControl.ActualWidth,
                                                       targetElementPoint.Y + targetControl.ActualHeight);
            }
            else
            {
                targetElementOppositePoint = new Point(targetElementPoint.X, targetElementPoint.Y);
            }

            var targetRect = new Rect(targetElementPoint.X, targetElementPoint.Y, (int)(targetElementOppositePoint.X), (int)(targetElementOppositePoint.Y));

            DwmQueryThumbnailSourceSize(thumbHandle, out var size);

            var props = new DwmThumbnailProperties
            {
                fVisible      = true,
                dwFlags       = DwmTnpVisible | DwmTnpRectdestination | DwmTnpOpacity,
                opacity       = 255,
                rcDestination = new WinApi.Rect(0, 0, 100, 100)
            };


            DwmUpdateThumbnailProperties(thumbHandle, ref props);
            return(thumbHandle);
        }
 protected override void AttachCore(UIElement element)
 {
     if (description == null)
     {
         string str = element.GetType().Name;
         description = str;
     }
 }
Ejemplo n.º 4
0
        private void InitializeView(UIElement view) {
            var type = view.GetType();

            var initializeMethod = type.GetMethod("InitializeComponent", BindingFlags.Public | BindingFlags.Instance);

            if (initializeMethod == null)
                return;

            initializeMethod.Invoke(view, null);
        }
Ejemplo n.º 5
0
 public static void AnimateColor(SolidColorBrush from, SolidColorBrush to, UIElement control, double duration)
 {
     SolidColorBrush myBrush = new SolidColorBrush();
     myBrush = from;
     ColorAnimation myColorAnimation = new ColorAnimation();
     myColorAnimation.From = from.Color;
     myColorAnimation.To = to.Color;
     myColorAnimation.Duration = new Duration(TimeSpan.FromSeconds(duration));
     myBrush.BeginAnimation(SolidColorBrush.ColorProperty, myColorAnimation);
     control.GetType().GetProperty("Background").SetValue(control, myBrush);
 }
Ejemplo n.º 6
0
        internal static IEditable CreateWrapperForUIElement(CanvasEditor editor, UIElement element)
        {
            IEditable result = null;

            Assembly assembly = Assembly.GetAssembly(typeof(EditableWrapper));
            string name = element.GetType().Name;
            Type type = assembly.GetType(typeof(EditableWrapper).Namespace + ".Editable" + name);
            if (type != null)
            {
                result = (IEditable)Activator.CreateInstance(type, new object[] { editor, element });
            }

            return result;
        }
		private void FindByName(UIElement element, List<WildcardPattern> patterns, ref List<UIElement> results)
		{
			foreach (string content in _contentProperties)
			{
				Type type = element.GetType();
				var prop = type.GetProperty(content);
				if (prop != null)
				{
					var enumerable = prop.GetValue(element, null) as System.Collections.IEnumerable;
					if (enumerable != null)
					{
						foreach (object el in enumerable)
						{
							var fel = el as FrameworkElement;
							if (fel != null)
							{
								foreach (var pattern in patterns)
								{
									if (pattern.IsMatch(fel.Name))
									{
										results.Add(fel);
									}
								}
							}
						}
						foreach (object el in enumerable)
						{
							if (el is UIElement)
							{
								FindByName((UIElement)el, patterns, ref results);
							}
						}
					}
					else
					{
						var el = prop.GetValue(element, null) as UIElement;
						if (el != null)
						{
							var fel = el as FrameworkElement;
							if (fel != null)
							{
								foreach (var pattern in patterns)
								{
									if (pattern.IsMatch(fel.Name))
									{
										results.Add(fel);
									}
								}
								FindByName(fel, patterns, ref results);
							}
							else
							{
								FindByName(el, patterns, ref results);
							}
						}
					}
				}
				// if we didn't find it by now, just give up...
			}
		}
Ejemplo n.º 8
0
 private void RegisterEvent(UIElement element, string triggerEvent)
 {
   var eventRef = element.GetType().GetEvent(triggerEvent);
   if (eventRef != null)
   {
     var invokeMethod = eventRef.EventHandlerType.GetMethod("Invoke");
     var parameters = invokeMethod.GetParameters();
     if (parameters.Length == 2)
     {
       if (typeof(RoutedEventArgs).IsAssignableFrom(parameters[1].ParameterType))
       {
         eventRef.AddEventHandler(element, new RoutedEventHandler(InvokeProvider));
       }
       else if (typeof(EventArgs).IsAssignableFrom(parameters[1].ParameterType))
       {
         eventRef.AddEventHandler(element, new EventHandler(InvokeProvider));
       }
     }
   }
 }
Ejemplo n.º 9
0
        void IViewAware.AttachView(UIElement view)
        {
            if (this.View != null)
                throw new InvalidOperationException(String.Format("Tried to attach View {0} to ViewModel {1}, but it already has a view attached", view.GetType().Name, this.GetType().Name));

            this.View = view;

            this.logger.Info("Attaching view {0}", view);

            var viewAsFrameworkElement = view as FrameworkElement;
            if (viewAsFrameworkElement != null)
            {
                if (viewAsFrameworkElement.IsLoaded)
                    this.OnViewLoaded();
                else
                    viewAsFrameworkElement.Loaded += (o, e) => this.OnViewLoaded();
            }
        }