Windows Community Toolkit

repository·main·Indexed 21 days ago

https://github.com/communitytoolkit/windows

A collection of controls, helpers, and extensions for Windows application development. It supports WinUI 2, WinUI 3, and the Uno Platform, providing specialized packages for animations, behaviors, collections, converters, developer tools, media effects, and UI extensions across WindowsAppSDK, UWP, and Uno.WinUI/Uno.UI environments.

Tokens
41.2K
Snippets
109
Records
219
Agent score
77%

What's inside Windows Community Toolkit

  1. Overview of Sizer controls

    main

    The Sizer controls in the Windows Community Toolkit allow users to resize various parts of a UI experience in a consistent manner. The toolkit provides three primary types of Sizer controls:

    • GridSplitter: Used to resize rows or columns within a Grid.
    • ContentSizer: Designed to allow users to resize the content area of a control.
    • PropertySizer: Designed to allow users to resize property-related UI elements.

    These controls are part of the Controls category under the Sizers subcategory.

  2. Overview of CommunityToolkit.WinUI.Animations components

    main

    The CommunityToolkit.WinUI.Animations package provides several tools for managing animations within the CommunityToolkit.WinUI.Animations namespace, including:

    • AnimationBuilder: For constructing animation sequences.
    • AnimationSet: For managing groups of animations.
    • Connected Animations Helpers: Utilities for implementing connected animation transitions.
    • Expressions: For creating expression-based animations.
    • Implicit Animations: For defining animations that trigger automatically based on property changes.
    • ScrollViewerExtensions: Extension methods for animating or interacting with ScrollViewer controls.
  3. Use the RichSuggestBox control

    main

    The RichSuggestBox is a rich text input control that combines the functionality of an AutoSuggestBox and a RichEditBox. It allows users to type prefixes (like @ or #) to trigger suggestions. When a suggestion is selected, it is embedded into the document as a 'token'.

    Tokens are implemented as hyperlinks using a unique Guid as the link address, padded with Zero Width Spaces (ZWSP) to maintain the layout: \u200b + Prefix + Display Text + \u200b.

    <controls:RichSuggestBox
      PlaceholderText="Leave a comment"
      ItemTemplate="{StaticResource SuggestionTemplate}"
      Prefixes="@#" />
  4. Use the CameraPreview control

    main

    The CameraPreview control allows you to preview video from available camera frame source groups. It can also be used to subscribe to real-time video frames and software bitmaps as they arrive from the selected camera source. The control only displays frame sources that support color video preview or video record streams.

    <controls:CameraPreview x:Name="CameraPreviewControl"/>
  5. Clip content using ClipToBounds

    main

    The ClipToBounds property on a UIElement determines whether the content of that element (including its child elements) is clipped to fit within the element's bounds. This is useful for preventing child elements from rendering outside the parent's designated area.

    You can enable this behavior directly in XAML by setting the ClipToBounds property to True on the target element.

    <!-- Example of clipping a target element in XAML -->
    <Grid ClipToBounds="True">
        <!-- Content that would otherwise overflow the Grid's bounds will be clipped -->
    </Grid>
  6. Use the WrapPanel control for flow layouts

    main

    The WrapPanel control positions child elements sequentially. It automatically breaks content to the next line (or column) when the edge of the containing box is reached.

    Key behaviors:

    • Orientation:
      • Horizontal (default): Positions controls from left to right. When the max width is reached, it creates a new row.
      • Vertical: Positions controls from top to bottom. When the max height is reached, it creates a new column.
    • Spacing:
      • In Horizontal orientation: HorizontalSpacing adds space between items in a row; VerticalSpacing adds space between rows.
      • In Vertical orientation: HorizontalSpacing adds space between columns; VerticalSpacing adds space between items in a column.
    • Stretching: If StretchChild="Last" is set, the last child will stretch to fill the remaining space, provided the available measure size is finite. If the panel is measured with infinite width (for horizontal) or infinite height (for vertical), the last child will not stretch.
    <controls:WrapPanel 
        Orientation="Vertical" 
        HorizontalSpacing="10" 
        VerticalSpacing="10" />
  7. Configure Notification overrides in StackedNotificationsBehavior

    main

    While the behavior uses the properties of the attached InfoBar (like ContentTemplate or IsIconVisible) by default, you can use the Notification class to provide specific overrides for individual messages.

    Important: Setting properties on the Notification object modifies the parent InfoBar directly. This can break XAML bindings on the InfoBar. To avoid this, only set constant properties on the parent InfoBar and use Notification options for any dynamic or message-specific values.

  8. Use WrapLayout for automatic content wrapping

    main

    The WrapLayout is a layout panel that virtualizes child elements in sequential order. It automatically breaks content to the next line (or column) when the edge of the containing box is reached.

    Orientation Behavior

    • Horizontal (Default): Positions controls from left to right. Once the MaxWidth is reached, it creates new rows.
    • Vertical: Positions controls from top to bottom. Once the MaxHeight is reached, it creates new columns.

    Spacing

    Spacing is applied uniformly between items using the following properties:

    • HorizontalSpacing:
      • In Horizontal orientation: Adds spacing between individual items in a row.
      • In Vertical orientation: Adds spacing between columns of items.
    • VerticalSpacing:
      • In Horizontal orientation: Adds spacing between rows of items.
      • In Vertical orientation: Adds spacing between individual items in a column.
    <controls:WrapLayout Orientation="Horizontal" 
                        HorizontalSpacing="10" 
                        VerticalSpacing="10" />