New to Telerik UI for WPF? Download free 30-day trial

Show desktop alert with message in RadChat

Environment

Product RadChat for WPF

Description

How to display alert, when a message is sent.

Solution

Handle the SendMessage event of the RadChat control, create a RadDesktopAlert and set its Content to a new MessageGroupViewModel. We are going to use the MessageGroup control to display the new message in the alert, however it can be replaced by a custom DataTemplate as well.

<Grid xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" 
     xmlns:chat="clr-namespace:Telerik.Windows.Controls.ConversationalUI;assembly=Telerik.Windows.Controls.ConversationalUI"  
     x:Name="grid"> 
    <Grid.Resources> 
        <DataTemplate x:Key="ChatTemplate"> 
            <chat:MessageGroup /> 
        </DataTemplate> 
    </Grid.Resources> 
    <telerik:RadChat x:Name="chat" SendMessage="chat_SendMessage" /> 
</Grid> 

private void chat_SendMessage(object sender, SendMessageEventArgs e) 
{ 
    RadDesktopAlertManager manager = new RadDesktopAlertManager(AlertScreenPosition.BottomRight, new Point(0, 0), 10); 
    var chat = sender as RadChat; 
    var viewmodel = new MessageGroupViewModel(e.Message.Author); 
    viewmodel.Messages.Add((e.Message as IInlineMessage).InlineViewModel); 
 
    var alert = new RadDesktopAlert 
    { 
        Header = chat.CurrentAuthor.Name, 
        Content = viewmodel, 
        ContentTemplate = this.grid.FindResource("ChatTemplate") as DataTemplate, 
        ShowDuration = 5000, 
    }; 
 
    manager.ShowAlert(alert); 
} 

See Also

In this article