tabcontrol

Cant get a control from a TabControl DataTemplate

五迷三道 提交于 2019-12-01 19:19:25
I've been googling this for the last 2 days and cant get anywhere, I just cant do anything to any control in a datatemplate of a tabcontrol. First off, the code: private void Window_Loaded(object sender, RoutedEventArgs e) { tabControl1.ItemsSource = new string[] { "TabA", "TabB", "TabC" }; } private void tabControl1_SelectionChanged(object sender, SelectionChangedEventArgs e) { ContentPresenter cp = tabControl1.Template.FindName("PART_SelectedContentHost", tabControl1) as ContentPresenter; DataTemplate dt = tabControl1.ContentTemplate; Grid g = tabControl1.ContentTemplate.FindName("myGrid",

Is there a way to cancel TabControl.Items.CurrentChanging?

空扰寡人 提交于 2019-12-01 18:19:17
There is unfortunately no TabControl.SelectionChanging event (Selector.SelectionChanging), I am struggling to implement this behavior so I can cancel the changing request. I tried to handle the TabControl.Items.CurrentChanging (the Items property is and ItemCollection ) event setting e.Cancel (of the CurrentChangingEventArgs ) to true, but the UI is is updated with the new tab although the item is not changed in the collection. Is there any way to prevent user from switching to a different TabItem when a condition is dissatisfied? ThomasAndersson I don't know the exact reason why this happens,

Adding buttons to a TabControl Tab in C#

℡╲_俬逩灬. 提交于 2019-12-01 18:02:15
I have a TabControl in a windows form. I have pragmaticly added new tabs like so: for (int i = 1; i < numOfLanguages; i++) { // add a tab for each language string tabTitle = split[i]; TabPage newTab = new TabPage(tabTitle); languageTabs.TabPages.Add(newTab); } inside the loop I want to set up the other controlls for each tab. mainly I want to add buttons. I have seen this code: tabPage1.Controls.Add(new Button()); Based off this example I want to do something similar like: languageTabs.SelectTab(split[i]).Add(new Button()); I know that this code wont work. Have been looking through the params

Is there a way to cancel TabControl.Items.CurrentChanging?

邮差的信 提交于 2019-12-01 17:54:08
问题 There is unfortunately no TabControl.SelectionChanging event (Selector.SelectionChanging), I am struggling to implement this behavior so I can cancel the changing request. I tried to handle the TabControl.Items.CurrentChanging (the Items property is and ItemCollection ) event setting e.Cancel (of the CurrentChangingEventArgs ) to true, but the UI is is updated with the new tab although the item is not changed in the collection. Is there any way to prevent user from switching to a different

Adding buttons to a TabControl Tab in C#

≯℡__Kan透↙ 提交于 2019-12-01 17:43:23
问题 I have a TabControl in a windows form. I have pragmaticly added new tabs like so: for (int i = 1; i < numOfLanguages; i++) { // add a tab for each language string tabTitle = split[i]; TabPage newTab = new TabPage(tabTitle); languageTabs.TabPages.Add(newTab); } inside the loop I want to set up the other controlls for each tab. mainly I want to add buttons. I have seen this code: tabPage1.Controls.Add(new Button()); Based off this example I want to do something similar like: languageTabs

How do I tell which tab you are moving from/to in a WinForms tab control?

你。 提交于 2019-12-01 16:33:09
I need to determine which tab the user is coming from, and going to, when they switch tabs, and possibly cancel the switch. I have tried the Deselecting, Deselected, Selecting, Selected events, and all of them show the e.TabPageIndex to be the same as the sender.SelectedIndex. Is there an event, or property, that I can use so that I can determine both sides of this, or do I have to hack something together with caching it from one event and using that value in the new event. I am trying to avoid handling the Deselecting/Deselected events and caching the value to use in the Selecting event. I

How do I tell which tab you are moving from/to in a WinForms tab control?

筅森魡賤 提交于 2019-12-01 15:29:29
问题 I need to determine which tab the user is coming from, and going to, when they switch tabs, and possibly cancel the switch. I have tried the Deselecting, Deselected, Selecting, Selected events, and all of them show the e.TabPageIndex to be the same as the sender.SelectedIndex. Is there an event, or property, that I can use so that I can determine both sides of this, or do I have to hack something together with caching it from one event and using that value in the new event. I am trying to

WPF Routed Command with Bindings per-Tab

我的梦境 提交于 2019-12-01 13:45:00
I intended to disable and enable the Buttons outside the TabControl, just like those inside the TabItem when the current tab is changed. But the CommandBindings of the TabItem do not seem to impact "up" the visual tree. What is the right way to do this? With this XAML: <Window x:Class="WpfApplication10.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:WpfApplication10" Title="MainWindow" Height="350" Width="525"> <StackPanel> <Button Content="MyCommand1" Command="local:MainWindow

Focus the controls in a Tabcontrol

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-01 12:54:38
问题 How can focus the controls when select a tabitem in a tabcontrol? 回答1: You should capture the Selection changed event of the TabControl and inside that you focus the control you need. Just as private void TabControl1_SelectionChanged(object sender, EventArgs e) { control1.Focus(); } 回答2: Not sure I understand what you're asking completely, but you probably want to capture the SelectionChanged event for the TabControl: public Window1() { InitializeComponent(); TabControl1.SelectionChanged +=

Lifetime of objects in a collection in VB.Net

↘锁芯ラ 提交于 2019-12-01 10:46:25
I'm trying to figure out the lifetime of the tmpTabPages in the following bit of code. Lets assume the form has an empty TabControl named MyTabControl, that there's a collection of strings called NameCollection. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load For Each itm In NameCollection Dim tmpTabPage as New TabPage(itm.toString) 'Add Controls to tmpTabPage MyTabControl.TabPages.Add(tmpTabPage) Next End Sub Since the scope of the tmpTabPage is the For/Next block, typically it's lifetime would be until the end of the block right? But