UWP UI Reference
This section provides detailed reference documentation for Universal Windows Platform (UWP) UI elements, controls, and related APIs.
Core UI Elements
TextBlock
Displays plain text. Supports rich text formatting.
TextBlock()
Properties
Text(string): The text content to display.FontSize(double): The size of the font.FontWeight(Windows.UI.Text.FontWeights): The weight of the font (e.g., Normal, Bold).Foreground(Windows.UI.Xaml.Media.Brush): The brush used to paint the text.
Example
XAML
<TextBlock Text="Hello, UWP!" FontSize="24" FontWeight="Bold" Foreground="DarkBlue"/>
Image
Displays an image from a specified source.
Image()
Properties
Source(Windows.UI.Xaml.Media.ImageSource): The image source. Can be a URI or a BitmapImage.Stretch(Windows.UI.Xaml.Media.Stretch): How the image should be scaled to fit the available space (e.g., Uniform, Fill).
Example
XAML
<Image Source="ms-appx:///Assets/logo.png" Stretch="Uniform"/>
Common Controls
Button
A clickable control that triggers an action.
Button()
Properties
Content(object): The content of the button, which can be text, an image, or other UI elements.Command(System.Windows.Input.ICommand): A command to be executed when the button is clicked.IsEnabled(bool): Indicates if the button is enabled.
Events
Click: Fired when the button is clicked.
Example
XAML
<Button Content="Click Me" Click="OnButtonClick"/>
C# (Code-behind)
private void OnButtonClick(object sender, RoutedEventArgs e)
{
// Handle button click
System.Diagnostics.Debug.WriteLine("Button clicked!");
}
TextBox
Allows users to enter and edit text.
TextBox()
Properties
Text(string): The current text in the TextBox.PlaceholderText(string): Text displayed when the TextBox is empty.IsReadOnly(bool): Determines if the user can edit the text.
Events
TextChanged: Fired when the text content changes.
Layout Panels
StackPanel
Arranges child elements in a single line, either horizontally or vertically.
StackPanel()
Properties
Orientation(Windows.UI.Xaml.Controls.Orientation):HorizontalorVertical.
Example
XAML
<StackPanel Orientation="Horizontal" Spacing="10">
<TextBlock Text="Item 1"/>
<TextBlock Text="Item 2"/>
</StackPanel>
Grid
Defines a flexible grid-based layout system.
Grid()
Properties
RowDefinitions(Windows.UI.Xaml.Controls.RowDefinitionCollection): Defines rows in the grid.ColumnDefinitions(Windows.UI.Xaml.Controls.ColumnDefinitionCollection): Defines columns in the grid.
Elements within a Grid can be positioned using Grid.Row and Grid.Column attached properties.
Further Information
For more comprehensive details on UWP UI development, please refer to the official Microsoft UWP documentation.