tabcontrol

Closing TabItem by clicking middle button

三世轮回 提交于 2019-12-06 10:09:19
问题 I have a problem. In my WPF application, if i press a tabItem with middle mouse button, this tabItem should close. Just like in FireFox. But I try to do this using MVVM, and i need to use commands. Also my tabItems are created dynamically. Help me plz! Thank you! 回答1: Create a DataTemplate for your tab items like this: <DataTemplate x:Key="ClosableTabTemplate"> <Border> <Grid> <Grid.InputBindings> <MouseBinding Command="ApplicationCommands.Close" Gesture="MiddleClick" /> </Grid.InputBindings>

How to get the Document's Title from a Web Browser control in wpf

a 夏天 提交于 2019-12-06 08:38:20
I have created a Web Browser control in a TabControl.I want to set the Header of the TabItem to the Document's title of the Web Browser. I used the following code in the Navigated Event of the WebBrowser dynamic doc = tabBrowser.Document; //tabBrowser is the name of WebBrowser Control tab.Header = doc.Title; //tab is the name of the Tab Item But this piece of code doesn't work as it should.The header changes only for a few site. How can i set the Header of the tabItem to the Document's Title Value? Here is the navigated function: public void tabBrowser_Navigated(object sender, System.Windows

TabControl blinks if image is background

*爱你&永不变心* 提交于 2019-12-06 07:15:36
问题 I have noticed that if I have a TabControl in a Panel that has an Image Background, when the mouse hovers over a tab it blinks and redraws. Is there a workaround to prevent this from happening? 回答1: I see it. It happens because TabControl draws itself partly by asking the parent control to draw itself inside its own window. Necessary because the tabs don't cover the full width of the control, they "stick out". If the BackgroundImage is slow to draw, you'll see a flicker between the background

How to cancel tab change in WPF TabControl

可紊 提交于 2019-12-06 06:24:30
I have found multiple questions about this problem on SO, however I still can't quite get a realiable solution. Here is what I came up with after reading the answers. Xaml: <Window x:Class="WpfApplication1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="300" Width="300" x:Name="this"> <TabControl IsSynchronizedWithCurrentItem="True" ItemsSource="{Binding Tabs, ElementName=this}" x:Name="TabControl"/> </Window> Code behind: public partial class MainWindow : Window { public MainWindow(

WPF Tab Control With No Tabs

荒凉一梦 提交于 2019-12-06 05:39:00
I would like to have a control similar to tab control but without the "TabStrip" part and have the tabs be changed by a combo box instead. how to I make this happen? I guess that the answer is out there I just fail to correctly phrase it in English. Don't use a tabcontrol for this. Use a ContentControl where you dynamically bind the content. <ContentControl Content="{Bindning MyDynamicContent}" /> The change the item that is stored in the MyDynamicContent property based on the checkboxes. You could also use a frame or grid or any of the content controls. I like the ContentControl answer as it

Silverlight TabItem Visibility not changing

假装没事ソ 提交于 2019-12-06 05:32:33
I have a TabControl with many TabItems binding to a ViewModel that has properties for each TabItem's Visibility. <sdk:TabControl> <sdk:TabItem Name="Inventory" Header="Inventory" Style="{StaticResource TabItemStyle}" Visibility="{Binding Permissions.Inventory, Converter={StaticResource PermissiveVisibilityConverter}, ConverterParameter='Viewer'}" DataContext="{Binding VM}" /> </sdk:TabControl> All TabItems are defaulted to a Visibility of collapsed. But when the VM changes a TabItem to Visible it does not work until you move your mouse over the control... Even if I set the visibility

WPF: Disable arrow-keys on tabcontrol

怎甘沉沦 提交于 2019-12-06 05:23:13
I'm using the WPF TabControl in my application in order to switch between different areas/functions of the program. One thing annoys me though. I have hidden the tabs so I can control the selectedtab, instead of the user. The user however, can still switch between tabs using the arrow-keys. I have tried using the KeyboardNavigation-attribute, but I can't get this working. Can this be disabled? You can hook on to the TabControl.PreviewKeyDown event for this one. Check to see if it's the left or right arrow and say that you've handled it. private void TabControl_PreviewKeyDown(object sender,

Change color of unused space of TabControl

拜拜、爱过 提交于 2019-12-06 05:00:33
I want to change the color of unused space in the right of TabPage headers. I tried to override the OnPaintBackground method of the window and it is working, this is the code I used: protected override void OnPaintBackground(PaintEventArgs e) { base.OnPaintBackground(e); Rectangle lasttabrect = tabControl1.GetTabRect(tabControl1.TabPages.Count - 1); RectangleF emptyspacerect = new RectangleF( lasttabrect.X + lasttabrect.Width + tabControl1.Left, tabControl1.Top + lasttabrect.Y, tabControl1.Width - (lasttabrect.X + lasttabrect.Width), lasttabrect.Height); Brush b = Brushes.BlueViolet; // the

How can I switch tabs programatically from within my ViewModel?

南笙酒味 提交于 2019-12-06 03:36:26
I have a MVVM desktop application. In my View, I have a TabControl . Any suggestions on the best practice to switch to a specific tab by changing a property on the ViewModel? I suppose it could be done with a SelectedTab property, but then the Tabs have to exist in the ViewModel, and the View must bind to the Tabs list in ViewModel. At the moment, the two tabs are static, in the sence that I won't be creating/deleting any dynamically during execution. So I create the tabs in the View, and they represent two different sets of control bound to the same ViewModel, so it's not a case of different

adding tabs to tabcontrol from inside usercontrol

最后都变了- 提交于 2019-12-06 03:13:32
How can I add tabs to a tabcontrol that exists in one usercontrol from another usercontrol that is contained within a tab itself?? Can I do it without passing in the tabcontrol as a parameter in the constructor, perhaps via some static global method? I've tried public static ObservableTabCollection FindCollectionFromUC(this DependencyObject depObject) { bool loop = true; var parent = (VisualTreeHelper.GetParent(depObject) as FrameworkElement); while (loop) { if (parent.GetType() is typeof(TabControl)) { loop = false; return ((ObservableTabCollection)((TabControl)parent).ItemsSource); } parent