WPF Controls

Windows Presentation Foundation (WPF) provides a rich set of controls that form the building blocks of user interfaces. These controls are highly customizable and can be used to create modern, visually appealing applications.

Common Controls

Button

The Button control is used to trigger an action when clicked. It can contain text, images, or other content.

<Button Content="Click Me" HorizontalAlignment="Center" VerticalAlignment="Center" />

Properties: Content, Command, Click event.

TextBlock

The TextBlock control is used to display formatted text. It supports inline formatting and can contain multiple paragraphs.

<TextBlock Text="This is some styled text." Foreground="Blue" FontSize="16" />

Properties: Text, Foreground, FontSize, FontFamily.

TextBox

The TextBox control allows users to input and edit text. It supports multi-line input and scrollbars.

<TextBox Name="myTextBox" Text="Enter text here..." AcceptsReturn="True" />

Properties: Text, IsReadOnly, MaxLength, AcceptsReturn.

ListView

The ListView control displays a collection of items, often in a list format. It's highly flexible for presenting data.

<ListView ItemsSource="{Binding MyItems}">
    <ListView.ItemTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding Name}" />
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

Properties: ItemsSource, SelectedItem, ItemTemplate.

Note: For more advanced data presentation with sorting, filtering, and editing capabilities, consider using the DataGrid control.

Layout Controls

WPF offers powerful layout panels like Grid, StackPanel, and DockPanel to arrange controls effectively.

Grid

The Grid panel arranges elements in rows and columns, similar to a table.

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition />
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="100" />
        <ColumnDefinition />
    </Grid.ColumnDefinitions>

    <TextBlock Text="Header" Grid.Row="0" Grid.Column="0" />
    <TextBox Grid.Row="1" Grid.Column="1" />
</Grid>