diff options
| author | Shlomo Hecht <shlomo@twine-s.com> | 2019-05-07 19:27:19 +0300 |
|---|---|---|
| committer | Shlomo Hecht <shlomo@twine-s.com> | 2019-05-07 19:27:19 +0300 |
| commit | 4635d671ecc0ac65372ebaaa7044230f44317c77 (patch) | |
| tree | 6630bf6940552c46ae2d0f90632d2c5fff4d848a /Software/Visual_Studio/Tango.SharedUI/Controls | |
| parent | 51f0a70bca80ccad4eae7c4abf0c09a6215540a9 (diff) | |
| parent | 952b8d7f3c81d6943d0bbf665b74ff58ab8c1201 (diff) | |
| download | Tango-4635d671ecc0ac65372ebaaa7044230f44317c77.tar.gz Tango-4635d671ecc0ac65372ebaaa7044230f44317c77.zip | |
Merge branch 'master' of https://twinetfs.visualstudio.com/Tango/_git/Tango
Diffstat (limited to 'Software/Visual_Studio/Tango.SharedUI/Controls')
| -rw-r--r-- | Software/Visual_Studio/Tango.SharedUI/Controls/NavigationControl.cs | 63 |
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 } } |
