TextBlock
A lightweight control for displaying read-only text.Properties
- Text: The text content (string)
- FontSize: Size of the font (double)
- FontWeight: Weight of the font -
Normal,Bold,Light, etc. - FontFamily: Font family name (string)
- FontStyle: Style of the font -
Normal,Italic,Oblique - Foreground: Text color (IBrush)
- Background: Background color (IBrush)
- TextAlignment: Alignment -
Left,Center,Right,Justify - TextWrapping: Wrapping mode -
NoWrap,Wrap,WrapWithOverflow - TextTrimming: Trimming mode -
None,CharacterEllipsis,WordEllipsis - TextDecorations: Underline, strikethrough, etc.
- LineHeight: Height of each line (double)
- MaxLines: Maximum number of lines to display (int)
Example
- XAML
- C#
Text Formatting
Use Run elements for inline formatting:Image
Displays image content from various sources.Properties
- Source: Image source (IImage)
- Stretch: How image is sized -
None,Fill,Uniform,UniformToFill - StretchDirection: Scaling direction -
Both,UpOnly,DownOnly
Example
- XAML
- C#
Stretch Modes
- None: Display at original size
- Fill: Stretch to fill (may distort)
- Uniform: Scale to fit (maintains aspect ratio)
- UniformToFill: Scale to fill (maintains aspect ratio, may crop)
Border
A control that decorates a child with a border and background.Properties
- Background: Background brush (IBrush)
- BackgroundSizing: How background is drawn -
InnerBorderEdge,CenterBorder,OuterBorderEdge - BorderBrush: Border color (IBrush)
- BorderThickness: Border width (Thickness)
- CornerRadius: Radius for rounded corners (CornerRadius)
- BoxShadow: Shadow effects (BoxShadows)
- Padding: Inner padding (Thickness)
- Child: Single child element
Example
- XAML
- C#
ProgressBar
Shows progress of an operation.Label
A control that displays text and can specify a target for keyboard focus.Separator
A line that separates items.Viewbox
A container that scales its child to fill available space.ContentControl
Base class for controls that display a single piece of content.Best Practices
- Use TextBlock for read-only text - It’s more lightweight than TextBox
- Optimize images - Use appropriate resolutions and formats
- Use vector graphics when possible - SVG/PathIcon scales better than bitmaps
- Apply borders judiciously - Too many borders can clutter the UI
- Consider accessibility - Ensure sufficient contrast for text
Styling Display Controls
Performance Tips
- TextBlock is more efficient than Label for simple text display
- Cache images when displaying the same image multiple times
- Use async loading for images from URLs
- Virtualize long lists of display controls