aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.SharedUI/Controls/NavigationControl.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Software/Visual_Studio/Tango.SharedUI/Controls/NavigationControl.cs')
-rw-r--r--Software/Visual_Studio/Tango.SharedUI/Controls/NavigationControl.cs63
1 files changed, 57 insertions, 6 deletions
diff --git a/Software/Visual_Studio/Tango.SharedUI/Controls/NavigationControl.cs b/Software/Visual_Studio/Tango.SharedUI/Controls/NavigationControl.cs
index 5ef543347..1ec273e43 100644
--- a/Software/Visual_Studio/Tango.SharedUI/Controls/NavigationControl.cs
+++ b/Software/Visual_Studio/Tango.SharedUI/Controls/NavigationControl.cs
@@ -6,6 +6,7 @@ using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
+using System.Windows.Forms.Integration;
using System.Windows.Markup;
using System.Windows.Media;
using System.Windows.Media.Animation;
@@ -294,12 +295,17 @@ namespace Tango.SharedUI.Controls
{
if (!_loaded)
{
+ _loaded = true;
+
if (Elements != null)
{
+ //foreach (var element in Elements.Where(x => x != SelectedElement))
+ //{
+ // LoadVisual(element);
+ //}
+
SelectedElement = Elements.FirstOrDefault();
}
-
- _loaded = true;
}
}
@@ -335,13 +341,35 @@ namespace Tango.SharedUI.Controls
var toAdd = Elements.Where(x => !_grid.Children.OfType<NavigationElement>().Select(y => y.Element).ToList().Contains(x)).ToList();
toRemove.ForEach(x => _grid.Children.Remove(x));
- toAdd.ForEach(x => _grid.Children.Add(
- new NavigationElement()
+
+ foreach (var x in toAdd)
+ {
+ var navigationElement = new NavigationElement()
{
RenderTransformOrigin = new Point(0.5, 0.5),
Element = x,
- Content = KeepElementsAttached ? x : null,
- }));
+ Content = x,
+ };
+
+ _grid.Children.Add(navigationElement);
+
+ if (!KeepElementsAttached)
+ {
+ bool loaded = false;
+
+ navigationElement.Loaded += (_, __) =>
+ {
+ if (!loaded)
+ {
+ if (x != SelectedElement)
+ {
+ loaded = true;
+ navigationElement.Content = null;
+ }
+ }
+ };
+ }
+ }
}
if (!Elements.Contains(SelectedElement))
@@ -550,6 +578,29 @@ namespace Tango.SharedUI.Controls
return element;
}
+ /// <remarks>
+ /// This method needs to be called in order for
+ // the element to print visibly at the correct size.
+ /// </remarks>
+ private static void LoadVisual(FrameworkElement element)
+ {
+ if (element.Parent == null)
+ {
+ try
+ {
+ System.Windows.Forms.UserControl controlContainer = new System.Windows.Forms.UserControl();
+ controlContainer.Width = 100;
+ controlContainer.Height = 100;
+ var host = new ElementHost() { Child = element, Dock = System.Windows.Forms.DockStyle.Fill };
+ controlContainer.Controls.Add(host);
+ IntPtr handle = controlContainer.Handle;
+ host.Child = null;
+ controlContainer.Dispose();
+ }
+ catch { }
+ }
+ }
+
#endregion
}
}