|
private async void sfChat_SendMessage(object sender, SendMessageEventArgs e)
{
e.Handled = true;
await Task.Delay(100);
sfChat.Editor.Text = string.Empty;
}
|
Hi Philip,
Thanks for using Syncfusion controls.
We have checked your query. you can achieve your requirement. The newly added message can be canceled from sending, in the SendMessage event handler and SendMessageCommand by setting the Handled value as true in the provided SendMessageEventArgs. And you can clear the editor text by setting the string.Empty to sfChat.Editor.Text. we have prepared the sample based on your requirement and attached for your reference you can download the same from the below link.
private async void sfChat_SendMessage(object sender, SendMessageEventArgs e){e.Handled = true;await Task.Delay(100);sfChat.Editor.Text = string.Empty;}
Regards,Sivaraman S
Are there any examples of how to do clear the editor text from a view model? We are driving the sending of messages through the `SendMessageCommand` and don't have direct access to the SfChat object.
Driving this through the code behind is not feasible as our send message handling includes some additional logic in the ViewModel.
|
<sfChat:SfChat x:Name="sfChat"
Messages="{Binding Messages}"
SendMessageCommand="{Binding SendMessageCommand}"
CurrentUser="{Binding CurrentUser}"
ShowOutgoingMessageAvatar="True" >
<sfChat:SfChat.Behaviors>
<local:ChatEditorBehavior viewModels="{x:Reference viewModel}"></local:ChatEditorBehavior>
</sfChat:SfChat.Behaviors>
</sfChat:SfChat> |
|
ChatEditorBehavior class
public class ChatEditorBehavior : Behavior<SfChat>
{
private GettingStartedViewModel viewModel;
public GettingStartedViewModel viewModels
{
get { return viewModel; }
set { viewModel = value; }
}
protected override void OnAttachedTo(SfChat bindable)
{
Binding editorbinding = new Binding("EditorText");
editorbinding.Source = viewModel;
editorbinding.Mode = BindingMode.TwoWay;
bindable.Editor.SetBinding(Editor.TextProperty, editorbinding);
base.OnAttachedTo(bindable);
}
}
SendMessageCommandExt class
public void Execute(object parameter)
{
(parameter as SendMessageEventArgs).Handled=true;
Device.BeginInvokeOnMainThread(() =>
{
viewmodel.EditorText = "";
});
}
|
|
ChatEditorBehavior class
public class ChatEditorBehavior : Behavior<SfChat>
{
private GettingStartedViewModel viewModel;
public GettingStartedViewModel viewModels
{
get { return viewModel; }
set { viewModel = value; }
}
protected override void OnAttachedTo(SfChat bindable)
{
MessagingCenter.Subscribe<GettingStartedViewModel>(this, "HandledSendMessage", (sender) =>
{
Device.BeginInvokeOnMainThread(() =>
{
bindable.Editor.Text = "";
});
});
base.OnAttachedTo(bindable);
}
}
SendMessageCommandExt class
public void Execute(object parameter)
{
(parameter as SendMessageEventArgs).Handled=true;
MessagingCenter.Send<GettingStartedViewModel>(viewmodel, "HandledSendMessage");
} |
Hello Suja,
Thank you for the timely response and solutions, I am unable to find any samples of the suggested solutions.
Thanks,
Thomas
Isn't there any straightforward solution so far MVVM rather than the one provided above?
| <sfChat:SfChat x:Name="sfChat" Messages="{Binding Messages}"
SendMessage="sfChat_SendMessage"
CurrentUser="{Binding CurrentUser}" ShowOutgoingMessageAvatar="True" ></sfChat:SfChat> private async void sfChat_SendMessage(object sender, SendMessageEventArgs e) {
e.Handled = true;
await Task.Delay(100);
sfChat.Editor.Text = string.Empty; } |
i was asking about the MVVM