Skip to content

Is a databinding a hashtable or something else? #107

Unanswered
jdhitsolutions asked this question in General
Is a databinding a hashtable or something else? #107
Jul 19, 2020 · 1 answer

I'm trying to make sense of the commands based on existing help. New-BurntToastNotification has a -DataBinding parameter. I also see the New-BTBinding command. I copied and modified an example.

$text1 = New-BTText -Content 'This is a test'
$text2 = New-BTText
$text3 = New-BTText -Content 'This more testing'
$progress = New-BTProgressBar -Title 'Things are happening' -Status 'Working on it' -Value 0.01
$image1 = New-BTImage -Source 'C:\scripts\db.png'
$image2 = New-BTImage -Source 'C:\scripts\db.png' -AppLogoOverride -Crop Circle
$image3 = New-BTImage -Source 'C:\scripts\db.png' -HeroImage
$binding1 = New-BTBinding -Children $text1, $text2, $text3, $image1, $progress -AppLogoOverride $image2 -HeroImage $image3

The example doesn't show what to do with it. I assumed I could use $binding1 as the parameter value.

toast -DataBinding $binding1

But $binding1 isn't a hashtable so this fails. Is this a documentation deficiency? Am I missing something? Or is there a type problem with the parameters?

Replies

1 suggested answer

Yeah, sorry this is a deficiency in my documentation. This has been a common scenario the past couple of weeks, which tells me this needs to be one of the first areas (out of all the documentation that's needed) to focus on.

It's also an unfortunate overlap in terminology.

"Binding" as generated by New-BTBinding is an element of the XML that describe the toast notification to Windows.

The full example there should probably be:

$text1 = New-BTText -Content 'This is a test'
$text2 = New-BTText
$text3 = New-BTText -Content 'This more testing'
$progress = New-BTProgressBar -Title 'Things are happening' -Status 'Working on it' -Value 0.01
$image1 = New-BTImage -Source 'C:\scripts\db.png'
$image2 = New-BTImage -Source 'C:\scripts\db.png' -AppLogoOverride -Crop Circle
$image3 = New-BTImage -Source 'C:\scripts\db.png' -HeroImage
$binding1 = New-BTBinding -Children $text1, $text2, $text3, $image1, $progress -AppLogoOverride $image2 -HeroImage $image3
$visual1 = New-BTVisual -BindingGeneric $binding1
$content1 = New-BTContent -Visual $visual1
Submit-BTNotification -Content $Toast1 -UniqueIdentifier 'Toast001'

This is generates the "content" of a toast and "submits" it to windows.

Taking a step back, you can get the default notification by running this:

New-BurntToastNotification

Or just using the toast alias. This is the equivalent of using these "advanced" functions:

$Text1 = New-BTText -Content 'Default Notification'
$ImagePath = Join-Path -Path (Get-Module BurntToast -ListAvailable).ModuleBase -ChildPath 'Images\BurntToast.png'
$Image1 = New-BTImage -Source $ImagePath[0] -AppLogoOverride -Crop Circle
$Audio1 = New-BTAudio -Source 'ms-winsoundevent:Notification.Default'

$Binding1 = New-BTBinding -Children $Text1 -AppLogoOverride $Image1
$Visual1 = New-BTVisual -BindingGeneric $Binding1
$Content1 = New-BTContent -Visual $Visual1 -Audio $Audio1

Submit-BTNotification -Content $Content1

Behind the scenes, this has generated some XML:

image

So then "data bindings"

This is surfaced as a hashtable that is used for update-able toast notifications. There's a blog post on this here

In short, databindings allows for "anchors" to be placed in your XML that can be updated.

I'm pulling this from another discussion but a demo is:

For your first toast, try this:

$FirstDataBinding = @{
    FirstLine = "Example Toast Heading"
    SecondLine = "This toast is still the original"
    ThirdLine = " "
    ProgressStatus = 'Backup progress...'
    ProgressValue = 0.1
    ProgressDisplay = "1/10"
}

$Progress = New-BTProgressBar -Status "ProgressStatus" -Value 'ProgressValue' -ValueDisplay 'ProgressDisplay'

New-BurntToastNotification -Text "FirstLine", "SecondLine", "ThirdLine" -UniqueIdentifier "ExampleToast" -DataBinding $FirstDataBinding -ProgressBar $Progress

Note that the three data elements in New-BTProgressBar reference values in $FirstDataBinding.

To update it, send through an updated data binding:

$SecondDataBinding = @{
    SecondLine = "This toast has been updated!"
    ThirdLine = "hello"
    ProgressStatus = 'Backup progress...'
    ProgressValue = 0.3
    ProgressDisplay = "4/10"
}

Update-BTNotification -UniqueIdentifier "ExampleToast" -DataBinding $SecondDataBinding

And continue until it's finished:

$ThirdDataBinding = @{
    SecondLine = "This toast has been updated!"
    ThirdLine = "hello"
    ProgressStatus = 'Backup progress...'
    ProgressValue = 0.7
    ProgressDisplay = "7/10"
}

Update-BTNotification -UniqueIdentifier "ExampleToast" -DataBinding $ThirdDataBinding

$FourthDataBinding = @{
    SecondLine = "This toast has been updated!"
    ThirdLine = "hello"
    ProgressStatus = 'Backup complete'
    ProgressValue = 1
    ProgressDisplay = "10/10"
}

Update-BTNotification -UniqueIdentifier "ExampleToast" -DataBinding $FourthDataBinding

(All of this does need better documentation, and it's on the way, but maybe not in 0.7.2 as that's going to have to be rushed so that PowerShell 7.1 doesn't break it.)

0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants