Back to Devexpress

XtraTabPage Class

windowsforms-devexpress-dot-xtratab-b0ac742c.md

latest10.3 KB
Original Source

XtraTabPage Class

A tab page.

Namespace : DevExpress.XtraTab

Assembly : DevExpress.XtraEditors.v25.2.dll

NuGet Package : DevExpress.Win.Navigation

Declaration

csharp
public class XtraTabPage :
    XtraPanel,
    IXtraTabPageExt,
    IXtraTabPage,
    IToolTipControlClient,
    IAnimatedItem,
    ISupportXtraAnimation,
    ISupportAdornerElementEx,
    ISupportAdornerElement,
    IUpdateAdornerUI,
    ISupportDXSkinColorsEx,
    ISupportDXSkinColors
vb
Public Class XtraTabPage
    Inherits XtraPanel
    Implements IXtraTabPageExt,
               IXtraTabPage,
               IToolTipControlClient,
               IAnimatedItem,
               ISupportXtraAnimation,
               ISupportAdornerElementEx,
               ISupportAdornerElement,
               IUpdateAdornerUI,
               ISupportDXSkinColorsEx,
               ISupportDXSkinColors

The following members return XtraTabPage objects:

Remarks

Tab pages display UI controls. A tab page has a header that can display an image and text.

The XtraTabControl stores tab pages in the XtraTabControl.TabPages collection. Use index notation to access specific tab pages.

Text and Image

Property NameDescription
TextSpecifies the tab header text.
ImageOptionsContains image-related settings.
StartAnimation()Starts the GIF animation.
StopAnimation()Stops the GIF animation.

Display Settings

SettingProperty Name
VisibilityPageVisible
AvailabilityPageEnabled
AppearanceAppearance / XtraTabControl.AppearancePage (general settings)

Example

The following code snippet creates a PersonViewModel class, a BindingSource with generic data, and an XtraTabControl with two tab pages. Each page contains DevExpress WinForms data editors bound to the corresponding properties of the shared data source.

csharp
using System.ComponentModel;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraTab;

namespace DXTabControlDemo {
    public partial class Form1 : XtraForm {
        public Form1() {
            InitializeComponent();
            // Create and configure BindingSource.
            BindingSource bindingSource = new BindingSource();
            bindingSource.DataSource = new PersonViewModel { Id = 1, Name = "John Doe", Email = "[email protected]" };

            // Create XtraTabControl.
            XtraTabControl tabControl = new XtraTabControl { Dock = DockStyle.Fill };

            // Create the first tab page.
            XtraTabPage tabPage1 = new XtraTabPage { Text = "General" };
            TextEdit textEditId = new TextEdit { Dock = DockStyle.Top };
            TextEdit textEditName = new TextEdit { Dock = DockStyle.Top };
            textEditId.DataBindings.Add("EditValue", bindingSource, nameof(PersonViewModel.Id));
            textEditName.DataBindings.Add("EditValue", bindingSource, nameof(PersonViewModel.Name));
            tabPage1.Controls.Add(textEditName);
            tabPage1.Controls.Add(textEditId);

            // Create the second tab page.
            XtraTabPage tabPage2 = new XtraTabPage { Text = "Contact" };
            TextEdit textEditEmail = new TextEdit { Dock = DockStyle.Top };
            textEditEmail.DataBindings.Add("EditValue", bindingSource, nameof(PersonViewModel.Email));
            tabPage2.Controls.Add(textEditEmail);

            // Add tab pages to the Tab control
            tabControl.TabPages.Add(tabPage1);
            tabControl.TabPages.Add(tabPage2);

            // Add the Tab control to the Form.
            Controls.Add(tabControl);
        }
    }
    // ViewModel
    public class PersonViewModel : INotifyPropertyChanged {
        int id;
        string name;
        string email;

        public int Id {
            get => id;
            set { id = value; OnPropertyChanged(nameof(Id)); }
        }

        public string Name {
            get => name;
            set { name = value; OnPropertyChanged(nameof(Name)); }
        }

        public string Email {
            get => email;
            set { email = value; OnPropertyChanged(nameof(Email)); }
        }

        public event PropertyChangedEventHandler PropertyChanged;
        void OnPropertyChanged(string propertyName) =>
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }
}
vb
Imports System.ComponentModel
Imports System.Windows.Forms
Imports DevExpress.XtraEditors
Imports DevExpress.XtraTab

Namespace DXTabControlDemo
    Partial Public Class Form1
        Inherits XtraForm

        Public Sub New()
            InitializeComponent()

            ' Create and configure BindingSource.
            Dim bindingSource As New BindingSource()
            bindingSource.DataSource = New PersonViewModel With {
                .Id = 1,
                .Name = "John Doe",
                .Email = "[email protected]"
            }

            ' Create XtraTabControl.
            Dim tabControl As New XtraTabControl() With {
                .Dock = DockStyle.Fill
            }

            ' Create the first tab page.
            Dim tabPage1 As New XtraTabPage() With {
                .Text = "General"
            }
            Dim textEditId As New TextEdit() With {
                .Dock = DockStyle.Top
            }
            Dim textEditName As New TextEdit() With {
                .Dock = DockStyle.Top
            }
            textEditId.DataBindings.Add("EditValue", bindingSource, NameOf(PersonViewModel.Id))
            textEditName.DataBindings.Add("EditValue", bindingSource, NameOf(PersonViewModel.Name))
            tabPage1.Controls.Add(textEditName)
            tabPage1.Controls.Add(textEditId)

            ' Create the second tab page.
            Dim tabPage2 As New XtraTabPage() With {
                .Text = "Contact"
            }
            Dim textEditEmail As New TextEdit() With {
                .Dock = DockStyle.Top
            }
            textEditEmail.DataBindings.Add("EditValue", bindingSource, NameOf(PersonViewModel.Email))
            tabPage2.Controls.Add(textEditEmail)

            ' Add tab pages to the Tab control
            tabControl.TabPages.Add(tabPage1)
            tabControl.TabPages.Add(tabPage2)

            ' Add the Tab control to the Form.
            Controls.Add(tabControl)
        End Sub
    End Class

    ' ViewModel
    Public Class PersonViewModel
        Implements INotifyPropertyChanged

        Private _id As Integer
        Private _name As String
        Private _email As String

        Public Property Id As Integer
            Get
                Return _id
            End Get
            Set(value As Integer)
                _id = value
                OnPropertyChanged(NameOf(Id))
            End Set
        End Property

        Public Property Name As String
            Get
                Return _name
            End Get
            Set(value As String)
                _name = value
                OnPropertyChanged(NameOf(Name))
            End Set
        End Property

        Public Property Email As String
            Get
                Return _email
            End Get
            Set(value As String)
                _email = value
                OnPropertyChanged(NameOf(Email))
            End Set
        End Property

        Public Event PropertyChanged As PropertyChangedEventHandler _
            Implements INotifyPropertyChanged.PropertyChanged

        Private Sub OnPropertyChanged(propertyName As String)
            RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propertyName))
        End Sub
    End Class
End Namespace

Implements

IXtraResizableControl

Inheritance

Object MarshalByRefObject Component Control ScrollableControl XtraScrollableControl XtraPanel XtraTabPage

See Also

XtraTabPage Members

DevExpress.XtraTab Namespace