private void OpenSubscriptionToolWindow(MenuCommandParameters menuInfo) { SubscriptionControl control = new SubscriptionControl(); if (string.IsNullOrWhiteSpace(menuInfo.Name)) { menuInfo.Name = "Add"; } if (menuInfo.MenuItemType == MenuCommandParameters.MenuType.Manage) { control.Publication = menuInfo.Name; control.IsNew = false; menuInfo.Caption = menuInfo.Name; } else { control.IsNew = true; menuInfo.Caption = "New Subscription"; } control.Database = menuInfo.Connectionstring; FabTabItem tab = new FabTabItem(); tab.Content = control; tab.Header = menuInfo.Caption; _parent.FabTab.Items.Add(tab); _parent.FabTab.SelectedIndex = _parent.FabTab.Items.Count - 1; return; }
private DependencyObject CreateNewFabTabItemAndWireUpClosingEvent() { FabTabItem newClosableTabItem = new FabTabItem(); newClosableTabItem.TabClosing += new RoutedEventHandler(newClosableTabItem_TabClosing); return(newClosableTabItem); }
protected void NavPaneButton_Click(object sender, RoutedEventArgs e) { string tabName = ((NavigationPaneButton)sender).Name.ToString(); bool flag = false; if (this.tabControl.Items.Count > 0) { foreach (var mainItem in tabControl.Items) { if (((Control)mainItem).Name == tabName) { tabControl.SelectedItem = mainItem; flag = true; return; } } } if (!flag) { FabTabItem item = new FabTabItem(); item.Name = tabName; item.Header = tabName; item.TabClosing+=new RoutedEventHandler(item_TabClosing); StackPanel s = new StackPanel(); item.Content = s; s.Children.Add(new TextBlock() { Text = tabName }); tabControl.Items.Add(item); tabControl.SelectedItem = item; } }
void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) { switch (connectionId) { case 1: #line 309 "..\..\CancelCloseEventWindow.xaml" ((System.Windows.Controls.Button)(target)).Click += new System.Windows.RoutedEventHandler(this.Button_Click); #line default #line hidden return; case 2: this.mySplitTabControl = ((FabTab.FabTabControl)(target)); return; case 3: this.myConcreteTabItem = ((FabTab.FabTabItem)(target)); #line 328 "..\..\CancelCloseEventWindow.xaml" this.myConcreteTabItem.TabClosing += new System.Windows.RoutedEventHandler(this.ClosableTabItem_TabClosing); #line default #line hidden return; } this._contentLoaded = true; }
private void Button_Click(object sender, RoutedEventArgs e) { FabTabItem tab3 = new FabTabItem(); tab3.Content = new SampleView(); tab3.Header = "Tab 3"; myTabControl.Items.Add(tab3); }
private FabTabItem GetItemContainer(FrameworkElement element, FabTabItem item) { if (item == null) { item = _tabControl.ItemContainerGenerator.ContainerFromItem(element) as FabTabItem; } return GetItemFromHiddenListViewIfNecessary(element, item); }
private static BitmapSource GetBitmapSourceForWinFormsContent(FabTabItem fabTab) { System.Windows.Forms.Control control = ((WindowsFormsHost)fabTab.Content).Child; System.Drawing.Bitmap bit = new System.Drawing.Bitmap(control.Width, control.Height); control.DrawToBitmap(bit, new System.Drawing.Rectangle(0, 0, control.Width, control.Height)); BitmapSource source = loadBitmap(bit); return source; }
private FabTabItem GetItemContainer(FrameworkElement element, FabTabItem item) { if (item == null) { item = _tabControl.ItemContainerGenerator.ContainerFromItem(element) as FabTabItem; } return(GetItemFromHiddenListViewIfNecessary(element, item)); }
private FabTabItem GetItemFromHiddenListViewIfNecessary(FrameworkElement element, FabTabItem item) { //handle the case where they're binding tab's itemsource property to model object using datatemplates if (element is ListViewItem) { item = _tabControl.ItemContainerGenerator.ContainerFromItem((element as ListViewItem).Content) as FabTabItem; } return item; }
private void WireTabClosingEvent(object item) { FabTabItem tabItem = item as FabTabItem; if (tabItem != null) { tabItem.TabClosing += new RoutedEventHandler(newClosableTabItem_TabClosing); } }
private static BitmapSource GetBitmapSourceForWinFormsContent(FabTabItem fabTab) { System.Windows.Forms.Control control = ((WindowsFormsHost)fabTab.Content).Child; System.Drawing.Bitmap bit = new System.Drawing.Bitmap(control.Width, control.Height); control.DrawToBitmap(bit, new System.Drawing.Rectangle(0, 0, control.Width, control.Height)); BitmapSource source = loadBitmap(bit); return(source); }
private void GetAddedFabTabItemAndWireUpClosingEvent(System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { FabTabItem newClosableTabItem = this.FindFabTabFromItem(e.NewItems[0]); if (newClosableTabItem != null) { newClosableTabItem.TabClosing += new RoutedEventHandler(newClosableTabItem_TabClosing); } }
public BitmapSource GetBitmapSourceFromElement(FrameworkElement element) { FabTabItem fabTabItem = element as FabTabItem; if (fabTabItem != null && fabTabItem.Content is WindowsFormsHost) { return(GetBitmapSourceForWinFormsContent(fabTabItem)); } return(CreateBitmap(element)); }
private void AddFabTabItemHeaderIntoContentTabDropDown(object item) { if (!(item is ContentTabView || item is ContentTabItem)) { FabTabItem tabItem = this.FindFabTabFromItem(item); if (tabItem != null) { InsertUniqueHeader(tabItem); } } }
private void OpenSqlEditorToolWindow(MenuCommandParameters menuInfo, string script) { SqlEditorControl editor = new SqlEditorControl(); editor.Database = menuInfo.Connectionstring; editor.SqlText = script; FabTabItem tab = new FabTabItem(); tab.Content = editor; tab.Header = menuInfo.Caption; _parentWindow.FabTab.Items.Add(tab); _parentWindow.FabTab.SelectedIndex = _parentWindow.FabTab.Items.Count - 1; return; }
private void SelectEachTabAndUpdateItsLayout() { _tabControl.Items.ForEach(delegate(object item) { FabTabItem tabItem = _tabControl.FindFabTabFromItem(item); if (tabItem != null) { tabItem.IsSelected = true; _tabControl.UpdateLayout(); } }); }
void imageButtonCommandExecuted(object sender, ExecutedRoutedEventArgs args) { ImageButton imageButton = sender as ImageButton; if (imageButton != null) { int indexOfClickedButton = _contentTabView.ChildButtonCollection.IndexOf(imageButton); FabTabItem tabItem = _tabControl.ItemContainerGenerator.ContainerFromIndex(indexOfClickedButton + 1) as FabTabItem; if (tabItem != null) { tabItem.OnRaiseTabClosingEvent(new RoutedEventArgs(FabTabItem.TabClosingEvent, tabItem)); } } }
private Dictionary <object, object> BuildDictionaryOfViewsAndHeaders() { Dictionary <object, object> namedContentList = new Dictionary <object, object>(); foreach (object item in this.Items) { FabTabItem tabItem = this.FindFabTabFromItem(item); if (tabItem != null) { namedContentList.Add(item, tabItem.Header); } } return(namedContentList); }
private void ResetDragDropAdvisors() { if (this.SelectedItem != null) { FabTabItem lastTabItem = this.ItemContainerGenerator.ContainerFromIndex(this.Items.Count - 1) as FabTabItem; if (lastTabItem != null) { //when a tab closes that happens be the source or target on either of the advisors //it will disallow further drag and drop operations. therefore whenever a tab closes //reset this to something valid, in this case, the last item in the collection. DragDropManager.GetDragSourceAdvisor(lastTabItem).SourceUI = lastTabItem; DragDropManager.GetDropTargetAdvisor(lastTabItem).TargetUI = lastTabItem; } } }
void newClosableTabItem_TabClosing(object sender, RoutedEventArgs e) { //TODO: see if this check is redundant if (!e.Handled) { FabTabItem closingTab = e.OriginalSource as FabTabItem; GiveOtherEventHandlersAChanceToCancelTabClose(e, closingTab); if (closingTab != null && !e.Handled) { this.CloseTab(closingTab); e.Handled = true; ResetDragDropAdvisors(); } } }
void NoXamlWindow_Loaded(object sender, RoutedEventArgs e) { myTabControl = new FabTabControl(); FabTabItem tab1 = new FabTabItem(); tab1.Content = new SampleView(); tab1.Header = "Tab 1"; FabTabItem tab2 = new FabTabItem(); tab2.Content = new SampleView(); tab2.Header = "Tab 2"; myTabControl.Items.Add(tab1); myTabControl.Items.Add(tab2); grid.Children.Add(myTabControl); }
public void SetImageScreenshotOnFabTabItemAttachedProperty(FrameworkElement element, BitmapSource bitmap) { Image tooltipImage = CreateImageForToolTip(bitmap); FabTabItem item = element.Parent as FabTabItem; if (item == null) { item = element as FabTabItem; } item = GetItemContainer(element, item); if (item != null) { FabTabItemProperties.SetFabTabItemImage(item, tooltipImage); } else { throw new InvalidOperationException("Cannot create rich tooltip because FabTabItem cannot be resolved"); } }
private void SetupCloseButton(object view, ImageButton imageButton) { Button closeButton = imageButton.Template.FindName("PART_CloseButton", imageButton) as Button; FabTabItem currentItem = view as FabTabItem; if (currentItem == null) { currentItem = _tabControl.ItemContainerGenerator.ContainerFromItem(view) as FabTabItem; } if (currentItem.ShowCloseButton) { closeButton.Click += new RoutedEventHandler(closeButton_Click); closeButton.Command = new RoutedCommand(); CommandBinding b = new CommandBinding(closeButton.Command, new ExecutedRoutedEventHandler(imageButtonCommandExecuted)); imageButton.CommandBindings.Add(b); } else { closeButton.Visibility = Visibility.Hidden; } }
private FrameworkElement GetElementForSnapshot(FrameworkElement element) { //if we've got a tabitem, then grab it's content for the bitmap if (element is FabTabItem) { FabTabItem fabTab = element as FabTabItem; //thanks for the patch for WinForms interop butters877! if (fabTab.Content is WindowsFormsHost) { return(fabTab); } else { return((FrameworkElement)(element as FabTabItem).Content); } } else { return(element); } }
private void Button_Click_7(object sender, RoutedEventArgs e) { SampleView view = new SampleView(); view.LabelText = "A new view #" + (this.tabControl.Items.Count).ToString(); FabTabItem item = new FabTabItem(); Uri uri = new Uri("pack://application:,,/SampleProject;component/Graphics/tab_icon.gif", UriKind.RelativeOrAbsolute); BitmapImage bitmap = new BitmapImage(uri); //need to create these element factories to build up the datatemplates completely in code. //This would be much easier to define in XAML, but doing it here for demonstration purposes. //For more info on how this works see: http://stackoverflow.com/questions/248362/how-do-i-build-a-datatemplate-in-c-code FrameworkElementFactory spFactory = new FrameworkElementFactory(typeof(StackPanel)); spFactory.SetValue(StackPanel.OrientationProperty, Orientation.Horizontal); FrameworkElementFactory imgFactory = new FrameworkElementFactory(typeof(Image)); imgFactory.SetValue(Image.SourceProperty, bitmap); FrameworkElementFactory tbFactory = new FrameworkElementFactory(typeof(TextBlock)); //Very important to bind something in our datatemplate to the actual header so that it will show up. tbFactory.SetBinding(TextBlock.TextProperty, new Binding(".")); spFactory.AppendChild(imgFactory); spFactory.AppendChild(tbFactory); DataTemplate headerTemplate = new DataTemplate(); //set the datatemplate's visual tree to the root frameworkelementfactory. headerTemplate.VisualTree = spFactory; //build the visual tree for the HeaderTemplate, but the header itself needs to remain a string //if we want a meaningful string to show up for the screenshot headers on the ContentTabView //and meaningful tab header names to show up in the ContentTab dropdown. item.HeaderTemplate = headerTemplate; item.Header = view.LabelText; item.Content = view; this.tabControl.Items.Add(item); }
public static Image GetFabTabItemImage(FabTabItem fabTabItem) { return (Image)fabTabItem.GetValue(FabTabItemImageProperty); }
private void GiveOtherEventHandlersAChanceToCancelTabClose(RoutedEventArgs e, FabTabItem closingTab) { //first unwire the handler we are currently in from the event, //then raise the event from the tab again so that any subscribers beyond FabTabControl //in the chain can have the event handlers invoked first so they can choose to mark it handled //thereby cancelling the tab close. //Then rewire this handler to the TabClosing event. //This seems a bit hackish, but in the case of views that were added to the FabTabControl's //Items collection in XAML, by the time in codebehind that the consumer can subscribe to the //TabClosing event, the FabTabControl has already wired up this eventhandler. closingTab.RemoveHandler(e.RoutedEvent, new RoutedEventHandler(newClosableTabItem_TabClosing)); closingTab.RaiseEvent(e); closingTab.AddHandler(e.RoutedEvent, new RoutedEventHandler(newClosableTabItem_TabClosing)); }
public static Image GetFabTabItemImage(FabTabItem fabTabItem) { return((Image)fabTabItem.GetValue(FabTabItemImageProperty)); }
public void SpawnReportViewerWindow(object sender, ExecutedRoutedEventArgs e) { try { var menuItem = sender as MenuItem; if (menuItem == null) return; var menuInfo = menuItem.CommandParameter as MenuCommandParameters; if (menuInfo == null) return; WindowsFormsHost wh = new WindowsFormsHost(); ReportGrid rg = new ReportGrid(); var ds = new DataSet(); using (IRepository repository = RepoHelper.CreateRepository(menuInfo.Connectionstring)) { var sqlText = string.Format(Environment.NewLine + "SELECT * FROM [{0}]", menuInfo.Name) + Environment.NewLine + "GO"; ds = repository.ExecuteSql(sqlText); } rg.DataSet = ds; rg.TableName = menuInfo.Name; wh.Child = rg; string tabTitle = System.IO.Path.GetFileNameWithoutExtension(menuInfo.Caption) + "-" + menuInfo.Name + "-Report"; bool alreadyThere = false; int i = -1; foreach (var item in _parent.FabTab.Items) { i++; if (item is FabTabItem) { FabTabItem ftItem = (FabTabItem)item; if (ftItem.Header.ToString() == tabTitle) { alreadyThere = true; } } } if (alreadyThere) { _parent.FabTab.SelectedIndex = i; _parent.FabTab.Focus(); } else { FabTabItem tab = new FabTabItem(); tab.Content = wh; tab.Header = tabTitle; _parent.FabTab.Items.Add(tab); _parent.FabTab.SelectedIndex = _parent.FabTab.Items.Count - 1; rg.Focus(); } return; } catch (System.IO.FileNotFoundException) { MessageBox.Show("Microsoft Report Viewer 2010 not installed, please download and install to use this feature http://www.microsoft.com/en-us/download/details.aspx?id=6442"); return; } catch (Exception ex) { MessageBox.Show(Helpers.DataConnectionHelper.ShowErrors(ex)); } }
public void SpawnDataEditorWindow(object sender, ExecutedRoutedEventArgs e) { try { var menuItem = sender as MenuItem; if (menuItem == null) return; var menuInfo = menuItem.CommandParameter as MenuCommandParameters; if (menuInfo == null) return; WindowsFormsHost wh = new WindowsFormsHost(); ResultsetGrid rg = new ResultsetGrid(); List<int> readOnlyColumns = new List<int>(); using (IRepository repository = RepoHelper.CreateRepository(menuInfo.Connectionstring)) { System.Collections.Generic.List<PrimaryKey> pks = repository.GetAllPrimaryKeys(); var tpks = repository.GetAllPrimaryKeys().Where(pk => pk.TableName == menuInfo.Name).ToList(); if (tpks.Count == 0) { rg.ReadOnly = true; } List<Column> cols = repository.GetAllColumns(); cols = cols.Where(c => c.TableName == menuInfo.Name).ToList(); int x = 0; foreach (Column col in cols) { if (col.AutoIncrementBy > 0 || col.RowGuidCol) { readOnlyColumns.Add(x); } x++; } } var sqlText = string.Format(Environment.NewLine + "SELECT TOP({0}) * FROM [{1}]", Properties.Settings.Default.MaxRowsToEdit, menuInfo.Name); rg.TableName = sqlText; rg.ConnectionString = menuInfo.Connectionstring; rg.Tag = wh; rg.ReadOnlyColumns = readOnlyColumns; wh.Child = rg; string tabTitle = System.IO.Path.GetFileNameWithoutExtension(menuInfo.Caption) + "-" + menuInfo.Name + "-Edit"; if (rg.ReadOnly) tabTitle = System.IO.Path.GetFileNameWithoutExtension(menuInfo.Caption) + "-" + menuInfo.Name + "-ReadOnly"; bool alreadyThere = false; int i = -1; foreach (var item in _parent.FabTab.Items) { i++; if (item is FabTabItem) { FabTabItem ftItem = (FabTabItem)item; if (ftItem.Header.ToString() == tabTitle) { alreadyThere = true; } } } if (alreadyThere) { _parent.FabTab.SelectedIndex = i; _parent.FabTab.Focus(); } else { FabTabItem tab = new FabTabItem(); tab.Content = wh; tab.Header = tabTitle; _parent.FabTab.Items.Add(tab); _parent.FabTab.SelectedIndex = _parent.FabTab.Items.Count - 1; rg.Focus(); } return; } catch (Exception ex) { MessageBox.Show(Helpers.DataConnectionHelper.ShowErrors(ex)); } }
public static void SetFabTabItemImage( FabTabItem fabTabItem, Image value) { fabTabItem.SetValue(FabTabItemImageProperty, value); }
private FabTabItem GetItemFromHiddenListViewIfNecessary(FrameworkElement element, FabTabItem item) { //handle the case where they're binding tab's itemsource property to model object using datatemplates if (element is ListViewItem) { item = _tabControl.ItemContainerGenerator.ContainerFromItem((element as ListViewItem).Content) as FabTabItem; } return(item); }
private DependencyObject CreateNewFabTabItemAndWireUpClosingEvent() { FabTabItem newClosableTabItem = new FabTabItem(); newClosableTabItem.TabClosing += new RoutedEventHandler(newClosableTabItem_TabClosing); return newClosableTabItem; }
public void OpenSqlEditorToolWindow(MenuCommandParameters menuInfo, string script) { SqlEditorControl editor = new SqlEditorControl(); editor.Database = menuInfo.Connectionstring; editor.SqlText = script; FabTabItem tab = new FabTabItem(); tab.Content = editor; string tabTitle = System.IO.Path.GetFileNameWithoutExtension(menuInfo.Caption) + "-" + menuInfo.Name; tab.Header = tabTitle; int i = -1; int insertAt = -1; foreach (var item in _parent.FabTab.Items) { i++; if (item is FabTabItem) { FabTabItem ftItem = (FabTabItem)item; if (ftItem.Header.ToString().StartsWith(tabTitle)) { insertAt = i; } } } if (insertAt > -1) { _parent.FabTab.Items.Insert(insertAt + 1, tab); if (_parent.FabTab.Items.Count == 3) insertAt = insertAt + 1; _parent.FabTab.SelectedIndex = insertAt + 1; } else { _parent.FabTab.Items.Add(tab); _parent.FabTab.SelectedIndex = _parent.FabTab.Items.Count - 1; } return; }