コード例 #1
0
        private void EmbeddAppInTab(ApplicationInstance appInstance)
        {
            // Create a new hosting-panel for the application to embedd
            Panel containerPanel;
            Panel mainPanel;

            if (appInstance.Item.Resize)
            {
                // Default mode, just have one panel which resizes to the available space
                mainPanel      = new Panel();
                containerPanel = mainPanel;
            }
            else
            {
                // Mode where the application has a fixed size.
                // Here we need two panels, where the outer one can scroll
                // and the inner one does not resize (will be the size of the app to embedd).
                var winFormsPanel = new Panel
                {
                    AutoScroll = true
                };
                var innerPanel = new Panel
                {
                    AutoSize = false
                };
                winFormsPanel.Controls.Add(innerPanel);
                mainPanel      = winFormsPanel;
                containerPanel = innerPanel;
            }
            // Create the win forms hosting control and add the panel
            var winFormsHost = new WindowsFormsHost {
                Child = mainPanel
            };

            // Create the application instance
            appInstance.ContainerPanel = containerPanel;
            appInstance.Removed       += AppInstance_Removed;

            // Create a new tab item with this panel
            var newTabItem = new TabItem
            {
                Header  = appInstance,
                Content = winFormsHost
            };

            // Associate the tab item with the app instance
            appInstance.TabItem = newTabItem;
            // Add the new tab item
            MyTab.Items.Add(newTabItem);
            // Select the new tab
            MyTab.SelectedIndex = MyTab.Items.Count - 1;

            // Wait until the tab is correctly added
            WpfTools.DoEvents();

            // Start and embedd the app
            appInstance.Embedd();
        }