Skip to main content

UWP - PivotItem header with image and text

UWP - PivotItem Header With Image & Text
The Pivot class represents a control that provides quick navigation of views within an app. The UWP app developers put a Pivot control in their app screen to present groups of content that a user can swipe through. The developers should use a Pivot as the top-level control on the app screen.

The following UWP app development tutorial code will demonstrate how we can show both the image and text inside a PivotItem’s header section. Here we put a Pivot control in the layout. This Pivot control shows three items. We put the items inside the Pivot using XAML UI elements. Inside each item’s header, we display both an icon and text.

The PivotItem class’s Header property gets or sets the header for the PivotItem. In the Pivot items header section, we placed a StackPanel container control. And inside the StackPanel control, we added a SymbolIcon control and a TextBlock control. The SymbolIcon control allows us to display an icon and the TextBlock control can show simple text. As a result, our Pivot controls show both the icon and text inside each item’s header.

The SymbolIcon class represents an icon that uses a glyph from the Segoe MDL2 Assets font as its content.

The TextBlock is the primary control for displaying read-only text in UWP apps. The UWP app developers can use it to display single-line or multi-line text, inline hyperlinks, and text with formatting like bold, italic, or underlined.
MainPage.xaml

<Page
    x:Class="UniversalAppTutorials.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:UniversalAppTutorials"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">
    <StackPanel 
        x:Name="StackPanel1" 
        Margin="50" 
        Orientation="Vertical"
        Background="AliceBlue"
        Padding="50"
        >
        <Pivot x:Name="Pivot1" Title="Pivot Example" 
               Background="LightPink" Padding="0,0,0,15">
            <PivotItem Background="LightSkyBlue">
                <PivotItem.Header>
                    <StackPanel>
                        <SymbolIcon Symbol="Attach"/>
                        <TextBlock Text="Attach"/>
                    </StackPanel>
                </PivotItem.Header>
                <StackPanel Orientation="Vertical" Padding="50">
                    <TextBlock
                        Text="Pivot Item 1 : Attach"
                        Margin="10"
                        />
                    <Viewbox MaxHeight="200" MaxWidth="200">
                        <SymbolIcon Symbol="Attach"/>
                    </Viewbox>
                </StackPanel>
            </PivotItem>
            <PivotItem Background="Bisque">
                <PivotItem.Header>
                    <StackPanel Orientation="Vertical">
                        <SymbolIcon Symbol="Delete"/>
                        <TextBlock Text="Delete"/>
                    </StackPanel>
                </PivotItem.Header>
                <StackPanel Orientation="Vertical" Padding="50">
                    <TextBlock
                        Text="Pivot Item 2: Delete"
                        Margin="10"
                        />
                    <Viewbox MaxWidth="200" MaxHeight="200">
                        <SymbolIcon Symbol="Delete"/>
                    </Viewbox>
                </StackPanel>
            </PivotItem>
            <PivotItem Background="LightSteelBlue">
                <PivotItem.Header>
                    <StackPanel Orientation="Vertical">
                        <SymbolIcon Symbol="Calculator"/>
                        <TextBlock Text="Calculator"/>
                    </StackPanel>
                </PivotItem.Header>
                <StackPanel Orientation="Vertical" Padding="50">
                    <TextBlock
                        Text="Pivot Item 3 : Calculator"
                        Margin="10"
                        />
                    <Viewbox MaxWidth="200" MaxHeight="200">
                        <SymbolIcon Symbol="Calculator"/>
                    </Viewbox>
                </StackPanel>
            </PivotItem>
        </Pivot>
    </StackPanel>
</Page>

Popular posts from this blog

Restricting Jetpack Compose TextField to Numeric Input Only

Jetpack Compose has revolutionized Android development with its declarative approach, enabling developers to build modern, responsive UIs more efficiently. Among the many components provided by Compose, TextField is a critical building block for user input. However, ensuring that a TextField accepts only numeric input can pose challenges, especially when considering edge cases like empty fields, invalid characters, or localization nuances. In this blog post, we'll explore how to restrict a Jetpack Compose TextField to numeric input only, discussing both basic and advanced implementations. Why Restricting Input Matters Restricting user input to numeric values is a common requirement in apps dealing with forms, payment entries, age verifications, or any data where only numbers are valid. Properly validating input at the UI level enhances user experience, reduces backend validation overhead, and minimizes errors during data processing. Compose provides the flexibility to implement ...

jetpack compose - TextField remove underline

Compose TextField Remove Underline The TextField is the text input widget of android jetpack compose library. TextField is an equivalent widget of the android view system’s EditText widget. TextField is used to enter and modify text. The following jetpack compose tutorial will demonstrate to us how we can remove (actually hide) the underline from a TextField widget in an android application. We have to apply a simple trick to remove (hide) the underline from the TextField. The TextField constructor’s ‘colors’ argument allows us to set or change colors for TextField’s various components such as text color, cursor color, label color, error color, background color, focused and unfocused indicator color, etc. Jetpack developers can pass a TextFieldDefaults.textFieldColors() function with arguments value for the TextField ‘colors’ argument. There are many arguments for this ‘TextFieldDefaults.textFieldColors()’function such as textColor, disabledTextColor, backgroundColor, cursorC...

jetpack compose - Image clickable

Compose Image Clickable The Image widget allows android developers to display an image object to the app user interface using the jetpack compose library. Android app developers can show image objects to the Image widget from various sources such as painter resources, vector resources, bitmap, etc. Image is a very essential component of the jetpack compose library. Android app developers can change many properties of an Image widget by its modifiers such as size, shape, etc. We also can specify the Image object scaling algorithm, content description, etc. But how can we set a click event to an Image widget in a jetpack compose application? There is no built-in property/parameter/argument to set up an onClick event directly to the Image widget. This android application development tutorial will demonstrate to us how we can add a click event to the Image widget and make it clickable. Click event of a widget allow app users to execute a task such as showing a toast message by cli...