Hello,
The code in the attachment is used to better understand use of the ContentTemplate and Key parameters. I am using 19.4.0.53.
The logic is:
1. User clicks the button whose onclick event invokes the ShowToast() method.
2. The ShowToast() method invokes the component's ShowAsync() method, waits three seconds
and invokes the component's HideAsync() method.
3. The OnOpen handler updates the ToastModel to set the ContentTemplate and Key parameters.
4. The Opened and Closed handlers simply displays the Key parameter.
Observations:
1. When the Key parameter is static between invocations of the Toast: [see code fragment (1)]
a. The first time the button is clicked the Toast is displayed correctly and, after three
seconds, is hidden. The debug output confirms the Key parameter.
b. Subsequent clicks of the button display the Toast but it is never hidden.
2. When the value of Key changes between invocations of the Toast: [see code fragment (2)]
a. Every time the button is clicked, the Toast is displayed for three seconds
and then hidden.
3. A side issue...The ContentTemplate property can be defined on the control but seems to have
no effect. The only way to inject the ContentTemplate is through the ToastModel in the OnOpenHandler
method as shown in the code.
Question:
1. Is it really a requirement to change the Key parameter between invocation of the Toast?
2. Is the only method for setting the ContentTemplate parameter is through the ToastModel?
Peter
Attachment: Toast_Issue_f59fb04.zip
Thank you for the quick and, as always, professional response.
Query 1:
Understood. I was playing with the idea of using the same SfToast component to display toasts with different content and observed the behavior. In reality, I would have to track each toast so I can selectively hide them which, after more thought, would require discrete Key values.
Query 2:
My question was too general. Let me try to be specific. As observed, the component exposes the ContentTemplate parameter though seems to ignore its value.
As a demonstration, using the core originally provided, add ContentTemplate=@template to SfToast definition AND comment out the args.Options.ContentTemplate = template; in the OnOpenHandler() method. The toast is displayed with no content.
Examining the args.Options field when using a breakpoint in the OpenedHandler() method shows that both Content and ContentTemplate are null (which I assume are their default values).
So, to restate my question more specifically: Why is the ContentTemplate parameter ignored?
The following are the code changes described above:
<SfToast @ref=@ToastObj
Timeout=0
ContentTemplate=@template
>
<ToastEvents Opened=@OpenedHandler
OnOpen=@OnOpenHandler
Closed=@ClosedHandler
>
</ToastEvents>
</SfToast>
===AND===
private void OnOpenHandler(ToastBeforeOpenArgs args)
{
Debug.WriteLine("OnOpenHandler method invoked.");
//args.Options.ContentTemplate = template;
// (1): Use the following code to implement a static Key
args.Options.Key = toastKey;
// (2): Use the following code to implement a dynamic Key
//args.Options.Key = ++toastKey;
}
|
private async Task ShowToast() {
await this.ToastObj.ShowAsync(new ToastModel { ContentTemplate = template });
} |
Thanks for the response and the suggestion to set the ContentTemplate through a ToastModel. I used this method in the code submitted with this issue and, yes, it does work.
I will assume that the ContentTemplate parameter exposed by the SfToast component is actually not functional per my last post and lack of a direct response.
I truly appreciate Syncfusion's support of the community. I report my observations/questions as a way of "giving back". Your support staff is very helpful and, seemingly, appreciative of my comments and I am appreciative of your help.
Peter