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(); }
private void AppendEnumValue_Executed(object sender, ExecutedRoutedEventArgs e) { try { DataContainer.EnumValues.Add(new EnumValue("", "")); WpfTools.SetFocusOnNewCreatedColumn(DataGrid, DataContainer.EnumValues.Count - 1); } catch (Exception ex) { ShowAndLogMessage("exception caught", ex); } }
private void DeleteEnumValue_OnCanExecute(object sender, CanExecuteRoutedEventArgs e) { try { DataGrid dataGrid = e.Source as DataGrid; DependencyObject dep = e.OriginalSource as DependencyObject; if (dataGrid != null && dep != null) { if (dataGrid.Items.Count > 1) { var dataGridCell = WpfTools.SearchForParent(dep, typeof(DataGridCell), false); if (dataGridCell != null) { e.CanExecute = true; } } } } catch (Exception ex) { ShowAndLogMessage("exception caught", ex); } }
private void DeleteEnumValue_Executed(object sender, ExecutedRoutedEventArgs e) { try { DataGrid dataGrid = e.Source as DataGrid; DependencyObject dep = e.OriginalSource as DependencyObject; if (dataGrid != null && dep != null) { var dataGridRow = WpfTools.SearchForParent(dep, typeof(DataGridRow), false); if (dataGridRow != null) { int index = dataGrid.ItemContainerGenerator.IndexFromContainer(dataGridRow); if (index >= 0 && index < dataGrid.Items.Count) { DataContainer.EnumValues.RemoveAt(index); } } } } catch (Exception ex) { ShowAndLogMessage("exception caught", ex); } }