UWP Controls Reference
This section provides a comprehensive reference for common Universal Windows Platform (UWP) controls. These controls are fundamental building blocks for creating modern and responsive user interfaces on Windows.
TextBox
A control that allows the user to enter and edit text.
Key Properties:
- Text: Gets or sets the current text content of the TextBox.
- PlaceholderText: Gets or sets the text that is displayed when the TextBox is empty.
- IsReadOnly: Gets or sets a value indicating whether the TextBox is read-only.
- MaxLength: Gets or sets the maximum number of characters allowed in the TextBox.
Key Events:
- TextChanged: Raised when the text in the TextBox changes.
- Paste: Raised when content is pasted into the TextBox.
Example Usage (XAML):
<TextBox x:Name="MyTextBox" PlaceholderText="Enter your name" />
CheckBox
A control that represents a Boolean value.
Key Properties:
- IsChecked: Gets or sets a value indicating whether the control is checked.
- Content: Gets or sets the content of the CheckBox.
Key Events:
Example Usage (XAML):
<CheckBox Content="Remember me" IsChecked="True" />
ComboBox
A dropdown list that allows the user to select an item from a collection.
Key Properties:
- ItemsSource: Gets or sets a collection used to generate the items of the control.
- SelectedItem: Gets or sets the selected item.
- SelectedIndex: Gets or sets the index of the selected item.
- IsEditable: Gets or sets a value that indicates whether the ComboBox is editable.
Key Events:
- SelectionChanged: Raised when the selected item changes.
Example Usage (XAML):
<ComboBox x:Name="MyComboBox" Width="200">
<ComboBoxItem Content="Item 1" />
<ComboBoxItem Content="Item 2" />
<ComboBoxItem Content="Item 3" />
</ComboBox>
ListBox
A control that displays a list of items and allows the user to select one or more items.
Key Properties:
- ItemsSource: Gets or sets a collection used to generate the items of the control.
- SelectedItem: Gets or sets the selected item.
- SelectedIndex: Gets or sets the index of the selected item.
- SelectionMode: Gets or sets the selection mode for the ListBox.
Key Events:
- SelectionChanged: Raised when the selected item(s) change.
Example Usage (XAML):
<ListBox x:Name="MyListBox" SelectionMode="Multiple">
<ListBoxItem Content="Option A" />
<ListBoxItem Content="Option B" />
<ListBoxItem Content="Option C" />
</ListBox>
GridView
A control that displays a collection of items in a grid layout, with support for virtualization and adaptive sizing.
Key Properties:
- ItemsSource: Gets or sets a collection used to generate the items of the control.
- ItemTemplate: Gets or sets the DataTemplate that defines how items are displayed.
- SelectedItem: Gets or sets the selected item.
Key Events:
- SelectionChanged: Raised when the selected item changes.
Example Usage (XAML):
<GridView ItemsSource="{x:Bind MyCollection}">
<GridView.ItemTemplate>
<DataTemplate x:DataType="local:MyDataItem">
<StackPanel>
<TextBlock Text="{x:Bind Name}" />
<Image Source="{x:Bind ImageUrl}" />
</StackPanel>
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
Image
A control used to display an image.
Key Properties:
- Source: Gets or sets the Uniform Resource Identifier (URI) of the image source.
- Stretch: Gets or sets how the image content should be scaled to fit the destination bounds.
- Width: Gets or sets the width of the Image element.
- Height: Gets or sets the height of the Image element.
Example Usage (XAML):
<Image Source="Assets/logo.png" Width="100" Height="100" />
Slider
A control that allows the user to select a value from a range by moving a slider thumb.
Key Properties:
- Value: Gets or sets the current position of the slider thumb.
- Minimum: Gets or sets the minimum value of the slider.
- Maximum: Gets or sets the maximum value of the slider.
- Orientation: Gets or sets the orientation of the slider.
Key Events:
- ValueChanged: Raised when the Value property changes.
Example Usage (XAML):
<Slider x:Name="MySlider" Minimum="0" Maximum="100" Value="50" />
ProgressBar
A control that indicates the progress of an operation.
Key Properties:
- Value: Gets or sets the current progress value.
- IsIndeterminate: Gets or sets a value indicating whether the progress bar is indeterminate.
Example Usage (XAML):
<ProgressBar x:Name="MyProgressBar" Minimum="0" Maximum="100" Value="75" />
DatePicker
A control that allows the user to select a date.
Key Properties:
- Date: Gets or sets the selected date.
- CalendarIdentifier: Gets or sets the identifier of the calendar to use.
- DayVisible: Gets or sets a value indicating whether the day part is displayed.
- MonthVisible: Gets or sets a value indicating whether the month part is displayed.
- YearVisible: Gets or sets a value indicating whether the year part is displayed.
Key Events:
- DateChanged: Raised when the Date property changes.
Example Usage (XAML):
<DatePicker x:Name="MyDatePicker" />
TimePicker
A control that allows the user to select a time.
Key Properties:
- Time: Gets or sets the selected time.
- ClockIdentifier: Gets or sets the identifier of the clock to use.
- Header: Gets or sets the text label for the control.
Key Events:
- TimeChanged: Raised when the Time property changes.
Example Usage (XAML):
<TimePicker x:Name="MyTimePicker" />