Public/New-BTText.ps1
function New-BTText { <# .SYNOPSIS Creates a new Text Element for Toast Notifications. .DESCRIPTION The New-BTTextElement function creates a new Text Element for Toast Notifications. You can specify the text you want displayed in a Toast Notification as a string, or run the function without a paramter for a blank line. Each Text Element is the equivalent of one line in on a Toast Notification, long lines will wrap. .INPUTS String You cannot pipe input to this function. .OUTPUTS Text .EXAMPLE New-BTTextElement -Content 'This is a line with text!' Creates a Text Element that will show the string 'This is a line with text!' on a Toast Notification. .EXAMPLE New-BTTextElement Creates a Text Element that will show a blank line on a Toast Notification. .NOTES TODO: Implement hint-style (https://blogs.msdn.microsoft.com/tiles_and_toasts/2015/06/30/adaptive-tile-templates-schema-and-documentation/) Credit for most of the help text for this function go to the authors of the UWPCommunityToolkit library that this module relies upon. Please see the originating repo here: https://github.com/Microsoft/UWPCommunityToolkit .LINK https://github.com/Windos/BurntToast/blob/master/Help/New-BTText.md #> [CmdletBinding()] [OutputType([Microsoft.Toolkit.Uwp.Notifications.AdaptiveText])] param ( # The text to display. Data binding support added in Creators Update, only works for toast top-level text elements (But appears to not be working via PowerShell yet.) [Parameter()] [alias('Content')] [string] $Text, # The maximum number of lines the text element is allowed to display. For Toasts, top-level text elements will have varying max line amounts (and in the Anniversary Update you can change the max lines). # # Text on a Toast inside a group (not yet implemented) will behave identically to Tiles (default to infinity). [int] $MaxLines, # The minimum number of lines the text element must display. Note that for Toast, this property will only take effect if the text is inside a group (not yet implemented.) [int] $MinLines, # Supply this switch to enable text wrapping. For Toasts, this is true on top-level text elements, and false inside a group (not yet implemented.) # # Note that for Toast, setting wrap will only take effect if the text is inside a group (you can use HintMaxLines = 1 to prevent top-level text elements from wrapping). [switch] $Wrap, # The horizontal alignment of the text. Note that for Toast, this property will only take effect if the text is inside a group (not yet implemented.) [Microsoft.Toolkit.Uwp.Notifications.AdaptiveTextAlign] $Align, # The style controls the text's font size, weight, and opacity. Note that for Toast, the style will only take effect if the text is inside a group (not yet implemented.) [Microsoft.Toolkit.Uwp.Notifications.AdaptiveTextStyle] $Style, # The target locale of the XML payload, specified as a BCP-47 language tags such as "en-US" or "fr-FR". The locale specified here overrides any other specified locale, such as that in binding or visual. If this value is a literal string, this attribute defaults to the user's UI language. If this value is a string reference, this attribute defaults to the locale chosen by Windows Runtime in resolving the string. [string] $Language ) $TextObj = [Microsoft.Toolkit.Uwp.Notifications.AdaptiveText]::new() if ($Text) { $TextObj.Text = $Text } if ($MaxLines) { $TextObj.HintMaxLines = $MaxLines } if ($MinLines) { $TextObj.HintMinLines = $MinLines } if ($Wrap) { $TextObj.HintWrap = $Wrap } if ($Align) { $TextObj.HintAlign = $Align } if ($Style) { $TextObj.HintStyle = $Style } if ($Language) { $TextObj.Language = $Language } $TextObj } |