diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2019-05-07 16:10:45 +0300 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2019-05-07 16:10:45 +0300 |
| commit | b6a210c5b82c2cf0215e8cdb61e1ab2c1b43f0dd (patch) | |
| tree | ba79c2d4833fa28e4428b94f4da8b9e9eb876ca1 /Software/Visual_Studio/Tango.SharedUI | |
| parent | a895c48616d94c8be0ef33f0ce58d9457d5dfd1b (diff) | |
| download | Tango-b6a210c5b82c2cf0215e8cdb61e1ab2c1b43f0dd.tar.gz Tango-b6a210c5b82c2cf0215e8cdb61e1ab2c1b43f0dd.zip | |
Resolved PPC CPU usage by events.
Diffstat (limited to 'Software/Visual_Studio/Tango.SharedUI')
| -rw-r--r-- | Software/Visual_Studio/Tango.SharedUI/Controls/NavigationControl.cs | 63 | ||||
| -rw-r--r-- | Software/Visual_Studio/Tango.SharedUI/Tango.SharedUI.csproj | 3 |
2 files changed, 59 insertions, 7 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 } } diff --git a/Software/Visual_Studio/Tango.SharedUI/Tango.SharedUI.csproj b/Software/Visual_Studio/Tango.SharedUI/Tango.SharedUI.csproj index 53462afbf..4ee00a06e 100644 --- a/Software/Visual_Studio/Tango.SharedUI/Tango.SharedUI.csproj +++ b/Software/Visual_Studio/Tango.SharedUI/Tango.SharedUI.csproj @@ -58,6 +58,7 @@ <Reference Include="WindowsBase" /> <Reference Include="PresentationCore" /> <Reference Include="PresentationFramework" /> + <Reference Include="WindowsFormsIntegration" /> </ItemGroup> <ItemGroup> <Compile Include="..\Versioning\GlobalVersionInfo.cs"> @@ -237,7 +238,7 @@ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <ProjectExtensions> <VisualStudio> - <UserProperties BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UseGlobalSettings="False" BuildVersion_StartDate="2000/1/1" /> + <UserProperties BuildVersion_StartDate="2000/1/1" BuildVersion_UseGlobalSettings="False" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" /> </VisualStudio> </ProjectExtensions> </Project>
\ No newline at end of file |
