Xamarin的Telerik UI?下载30天免费试用

开始

本文将指导您完成添加控件所需的步骤RadChat控件。

1.设置应用程序

看看这些文章,并按照说明来设置你的应用程序:

2.添加所需的Telerik引用

你有两个选择:

  • 中的说明为Xamarin Nuget包添加Telerik UITelerik NuGet包服务器的话题。注意,RadChat控件没有单独的nuget包。

  • 手动添加对Telerik程序集的引用,使用所需的程序集检查下面的列表RadChat组件:

平台 程序集
可移植的 Telerik.XamarinForms.Common.dll
Telerik.XamarinForms.ConversationalUI.dll
Telerik.XamarinForms.DataControls.dll
Telerik.XamarinForms.Input.dll
Telerik.XamarinForms.Primitives.dll
安卓 Telerik.Xamarin.Android.Common.dll
Telerik.Xamarin.Android.Data.dll
Telerik.Xamarin.Android.Input.dll
Telerik.Xamarin.Android.List.dll
Telerik.Xamarin.Android.Primitives.dll
Telerik.XamarinForms.Common.dll
Telerik.XamarinForms.ConversationalUI.dll
Telerik.XamarinForms.DataControls.dll
Telerik.XamarinForms.Input.dll
Telerik.XamarinForms.Primitives.dll
iOS Telerik.Xamarin.iOS.dll
Telerik.XamarinForms.Common.dll
Telerik.XamarinForms.ConversationalUI.dll
Telerik.XamarinForms.DataControls.dll
Telerik.XamarinForms.Input.dll
Telerik.XamarinForms.Primitives.dll
UWP Telerik.Core.dll
Telerik.Data.dll
Telerik.UI.Xaml.Controls.Data.UWP.dll
Telerik.UI.Xaml.Input.UWP.dll
Telerik.UI.Xaml.Primitives.UWP.dll
Telerik.XamarinForms.Common.dll
Telerik.XamarinForms.ConversationalUI.dll
Telerik.XamarinForms.DataControls.dll
Telerik.XamarinForms.Input.dll
Telerik.XamarinForms.Primitives.dll

3.添加RadChat控件

您可以使用以下方法之一:

从工具箱中拖动控件。

看看下面关于如何使用工具箱的主题:

在XAML或c#中创建控件定义。

下面的代码片段显示了一个简单的RadChat定义:

除此之外,您还需要添加以下命名空间:

xmlns: telerikConversationalUI = " clr-namespace: Telerik.XamarinForms.ConversationalUI;装配= Telerik.XamarinForms.ConversationalUI”

因此,出于简单的演示目的,将定义一个示例echo bot。

公共类RepeatBotService {private Action onReceiveMessage;内部无效AttachOnReceiveMessage(Action onmessagerecreceived){此。onReceiveMessage = onmessagerecreceived;}内部无效SendToBot(字符串文本){任务。延迟(500)。ContinueWith(t => this.onReceiveMessage?.Invoke(text));}}

然后,初始化RepeatBotService并订阅聊天实例的Items集合的CollectionChanged事件:

private RepeatBotService私人作者botAuthor;public ChatGettingStartedXaml() {InitializeComponent();这一点。botService = new RepeatBotService();this.botService.AttachOnReceiveMessage (this.OnBotMessageReceived);这一点。botAuthor = new Author {Name = "botty"};((INotifyCollectionChanged) this.chat.Items)。CollectionChanged += ChatItems_CollectionChanged; ; }

最后,添加所需的事件处理程序:

private void ChatItems_CollectionChanged(对象sender, NotifyCollectionChangedEventArgs e) {if (e.c olectionchangedaction . add) {TextMessage chatMessage = (TextMessage) e.b ewitems [0];如果(chatMessage。Author == chat.Author) {this.botService.SendToBot(chatMessage.Text);}}} private void onbotmessagerecreceived (string message) {Device.BeginInvokeOnMainThread(() => {TextMessage TextMessage = new TextMessage();textMessage。数据=消息;textMessage。Author = this.botAuthor;textMessage。文本=消息; chat.Items.Add(textMessage); }); }

图1:RadChat开始

开始聊天

SDK浏览器QSF应用程序包含不同的例子,显示RadChat的主要功能。您可以在例子QSF本地文件夹Xamarin的Telerik UI安装。

另请参阅

在本文中
Baidu
map