:: Home

  login:         
  passwords:  

WPF FAQs

WPF General Questions
Concepts Element Tree
Concepts Dependency Property
Concepts Attached Property
Concepts Routed Events
Concepts Resources.
Concepts Animation
Concepts Freezable Object
Concepts Input and Commands.
Concepts Layouts
XAML Inline Styles and Templates
XAML XML Namespaces
XAML Code Behind
XAML Custom Class
XAML Type Converters
Content Model ItemControl
Content Model HeaderedItemsControl
Content Model HeaderedContentControl
Content Model Content Control
Content Model Decorator Content Model
Content Model Panel Content Model
Documents Serialization and Storage
Documents Annotations
Documents Flow Content
Documents Printing
Graphics and Multimedia Rendering Graphics
Graphics and Multimedia Animation and Timing
Graphics and Multimedia 2D Graphics
Graphics and Multimedia 3D Graphics
Graphics and Multimedia Visual Layer
Control Customization Adorners
Control Customization Stylable controls
Control Customization ControlTemplates
Data Data Binding
Data DragandDrop
Data Serialization
Globalization and Localization Attributes
Globalization and Localization Comments
Globalization and Localization Globalization Struc
Application and Deployment ClickOnce
Application and Deployment Frame
Application and Deployment Page
Application and Deployment Navigation
Application and Deployment Setup
Application and Deployment Window
Interoperability Message Loops Between
Interoperability Win32 in WPF
Interoperability WPF in Win32
Interoperability Windows Forms and WPF
Security Trusted Security
Security Partial Trust Security
Tools Microsoft Expression Blend
Tools ZAM3D
Tools XAMLPAD
Controls ToolTip
Controls TextBlock
Controls TabControl
Controls ProgressBar
Controls PrintDialog
Controls Popup
Controls TextBox
Controls Canvas
Controls ComboBox
Controls ListBox
Controls StatusBar
Controls ToolBar
Controls Context Menu
Controls Expander
Controls DocumentViewer
Controls FlowDocumentReader
Controls GroupBox
Controls GridSplitter
Controls Image
Controls Menu
Controls ScrollBar
Controls Slider
Controls RichTextBox
Controls Border
Controls Buttons

SilverLight Interview Qs

SAP Interview Questions

Oracle Interview Questions

PHP Interview Questions

Ajax Interview Questions

IIS 7.0

OOP Interview Questions

Ruby Interview Questions

Sql Server Interview Questions

Winforms Interview Questions

SharePoint 2007 Questions

Microsoft Crm Questions

Controls TabControl Interview Questions & FAQs

Questions and answers for Controls TabControl.

57. Controls TabControl

    57.1 How do I prevent the user from changing the selected tab page in a TabControl ?
    57.2 How do I dynamically hide and unhide tabs in a TabControl ?
    57.3 How do I make the tabs in a TabControl appear on the bottom instead of the right?
    57.4 How can I add a style to a TabItem that is used in the TabControl ?

57.1 How do I prevent the user from changing the selected tab page in a TabControl ?

You can use the TabPage's "Validating" event to prevent a new tab page selection.

The steps involved are given below.

1. Every time the user selects a new tab, make sure that the corresponding tab page gets the focus. You can do so as follows:

[C#]

private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
{
tabControl1.TabPages[tabControl1.SelectedIndex].Focus();
tabControl1.TabPages[tabControl1.SelectedIndex].CausesValidation = true;
}

Note that "CausesValidation" should be set to 'True' since you will be listening to the Validating event in the next step. You will also have to add some code when the TabControl is shown the very first time (like in the Form_Load event handler).

2. Listen to the TabPage's "Validating" event (which will be called when the user clicks on a different tab page) and determine whether the user can be allowed to change the selected tab page.

[C#]

using System.ComponentModel;
private void tabPage1_Validating( object sender, CancelEventArgs e )
{


if ( !checkValidated.Checked )
e.Cancel = true;
}


57.2 How do I dynamically hide and unhide tabs in a TabControl ?

It is a common mistake to try to use the "Visible" property of the Tab Page to make the tab invisible. But this does not work (The Visible property of the TabPage is essentially obsolete). The TabControl doesn't provide you an easy way to do so. The workaround is to remove and add the tab page from the TabControl whenever you want to hide / unhide it. Refer to "How do I programmatically insert or delete tab pages in a TabControl?" in this FAQ for more information.


57.3 How do I make the tabs in a TabControl appear on the bottom instead of the right?

Set the "TabControl.Alignment" property to 'TabAlignment.Bottom'.

[C#]

tabControl1.Alignment = TabAlignment.Bottom;

You can also change the tabs into buttons using the "Appearance" property and TabAppearance enums.


57.4 How can I add a style to a TabItem that is used in the TabControl ?


[XAML]

<Style TargetType="TabItem">

<Setter Property="BorderThickness" Value="3"/>

<Setter Property="BorderBrush" Value="Red"/>

<Setter Property="Background" Value="LightBlue"/>

<Setter Property="VerticalContentAlignment" Value="Center"/>

<Setter Property="HorizontalContentAlignment" Value="Center"/>

<Setter Property="Template">

<Setter.Value>

<ControlTemplate TargetType="{x:Type TabItem}">

<Border>

<Grid>

<Grid>

<Border CornerRadius="3,3,0,0" Background="{TemplateBinding Background}"

BorderBrush="{TemplateBinding BorderBrush}"

BorderThickness="{TemplateBinding BorderThickness}"/>

</Grid>

<Border BorderThickness="{TemplateBinding BorderThickness}"

Padding="{TemplateBinding Padding}">

<ContentPresenter ContentSource="Header"

HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"

VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>

</Border>

</Grid>

</Border>

</ControlTemplate>

</Setter.Value>

</Setter>

</Style>

bottom user control
::  Home :: Services ::  Prices ::  Request Quote
Copyright 2007, Megasolutions Ltd