aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.Core/ExtensionMethods
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2018-06-14 11:57:22 +0300
committerRoy Ben-Shabat <Roy@Twine-s.com>2018-06-14 11:57:22 +0300
commit03959e785f635697fcdf0f99aad9454fafbf4e2e (patch)
treedbaf0350a9fbf7502057f01a9b34fd2ff15df9fd /Software/Visual_Studio/Tango.Core/ExtensionMethods
parentcc08947f9bc9f1f98ab8835200fb7cda0494cff2 (diff)
downloadTango-03959e785f635697fcdf0f99aad9454fafbf4e2e.tar.gz
Tango-03959e785f635697fcdf0f99aad9454fafbf4e2e.zip
Improved UdpDiscoveryClient (I Think...).
Improved PPC NavigationManager by providing a way to navigate by module/view paths..
Diffstat (limited to 'Software/Visual_Studio/Tango.Core/ExtensionMethods')
-rw-r--r--Software/Visual_Studio/Tango.Core/ExtensionMethods/DependencyObjectExtensions.cs2
-rw-r--r--Software/Visual_Studio/Tango.Core/ExtensionMethods/FrameworkElementExtensions.cs133
2 files changed, 135 insertions, 0 deletions
diff --git a/Software/Visual_Studio/Tango.Core/ExtensionMethods/DependencyObjectExtensions.cs b/Software/Visual_Studio/Tango.Core/ExtensionMethods/DependencyObjectExtensions.cs
index a12ca4f7f..12eba6bb3 100644
--- a/Software/Visual_Studio/Tango.Core/ExtensionMethods/DependencyObjectExtensions.cs
+++ b/Software/Visual_Studio/Tango.Core/ExtensionMethods/DependencyObjectExtensions.cs
@@ -2,9 +2,11 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
+using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
+using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;
using System.Windows.Media.Animation;
diff --git a/Software/Visual_Studio/Tango.Core/ExtensionMethods/FrameworkElementExtensions.cs b/Software/Visual_Studio/Tango.Core/ExtensionMethods/FrameworkElementExtensions.cs
index 216f6ae0c..2193127cf 100644
--- a/Software/Visual_Studio/Tango.Core/ExtensionMethods/FrameworkElementExtensions.cs
+++ b/Software/Visual_Studio/Tango.Core/ExtensionMethods/FrameworkElementExtensions.cs
@@ -1,11 +1,14 @@
using System;
+using System.Collections;
using System.Collections.Generic;
using System.Linq;
+using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
+using System.Windows.Markup;
using Tango.Core.EventArguments;
public static class FrameworkElementExtensions
@@ -309,5 +312,135 @@ public static class FrameworkElementExtensions
#endregion
+ #region Loaded
+ /// <summary>
+ /// Registers for the element loaded event. if the element is already loaded will invoke the handler immediately.
+ /// </summary>
+ /// <param name="element">The element.</param>
+ /// <param name="handler">The handler.</param>
+ public static void RegisterForLoadedOrNow(this FrameworkElement element, EventHandler handler)
+ {
+ if (element.IsLoaded)
+ {
+ handler(element, new EventArgs());
+ }
+ else
+ {
+ bool isLoaded = false;
+
+ element.Loaded += (sender, e) =>
+ {
+ if (!isLoaded)
+ {
+ isLoaded = true;
+
+ handler(element, new EventArgs());
+ }
+ };
+ }
+ }
+
+ #endregion
+
+ /// <summary>
+ /// A recursive search for a child of type T in memory and not on logical/visual tree.
+ /// </summary>
+ /// <typeparam name="T"></typeparam>
+ /// <param name="element">The element.</param>
+ /// <returns></returns>
+ public static T FindChildOffline<T>(this FrameworkElement element) where T : DependencyObject
+ {
+ if (element == null) return null;
+
+ PropertyInfo contentProp = element.GetType().GetProperty("Child");
+
+ if (contentProp == null)
+ {
+ contentProp = element.GetType().GetProperty("Content");
+ }
+
+ if (contentProp != null)
+ {
+ var value = contentProp.GetValue(element);
+
+ if (value != null)
+ {
+ if (value.GetType() == typeof(T))
+ {
+ return (T)value;
+ }
+ else
+ {
+ return FindChildOffline<T>(value as FrameworkElement);
+ }
+ }
+ }
+
+ if (element is Panel)
+ {
+ foreach (var child in (element as Panel).Children.OfType<FrameworkElement>())
+ {
+ if (child.GetType() == typeof(T))
+ {
+ return child as T;
+ }
+ else
+ {
+ var result = FindChildOffline<T>(child);
+
+ if (result != null)
+ {
+ return result;
+ }
+ }
+ }
+ }
+
+ var contentAtt = element.GetType().GetCustomAttribute<ContentPropertyAttribute>();
+
+ if (contentAtt != null)
+ {
+ contentProp = element.GetType().GetProperty(contentAtt.Name);
+
+ if (contentProp != null)
+ {
+ var content = contentProp.GetValue(element);
+
+ if (content != null)
+ {
+ if (content is IEnumerable)
+ {
+ foreach (var child in (content as IEnumerable))
+ {
+ if (child.GetType() == typeof(T))
+ {
+ return child as T;
+ }
+ else
+ {
+ var result = FindChildOffline<T>(child as FrameworkElement);
+
+ if (result != null)
+ {
+ return result;
+ }
+ }
+ }
+ }
+ else
+ {
+ var result = FindChildOffline<T>(content as FrameworkElement);
+
+ if (result != null)
+ {
+ return result;
+ }
+ }
+ }
+ }
+ }
+
+ return null;
+ }
}