前端实现接收发送文本消息
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Interact;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@@ -19,34 +20,87 @@ namespace StormChatWPF
|
||||
/// </summary>
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
public static MainWindow Instence;
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
LoadContactsList();
|
||||
Instence = this;
|
||||
}
|
||||
private void AddUserList()
|
||||
private void LoadContactsList()
|
||||
{
|
||||
if (Chat.ContactsList.Any())
|
||||
{
|
||||
foreach (var user in Chat.ContactsList)
|
||||
{
|
||||
UsersList.Items.Add(user);
|
||||
UsersList.Items.Add(user.NickName);
|
||||
}
|
||||
}
|
||||
}//向联系人列表listview中添加元素
|
||||
|
||||
private void UsersList_Selected(object sender, RoutedEventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void UsersList_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
|
||||
if (UsersList.SelectedItem != null)
|
||||
{
|
||||
Chat.CurrentContact = Chat.ContactsList[UsersList.SelectedIndex];
|
||||
}
|
||||
}
|
||||
|
||||
private void Button_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
AddUserList();
|
||||
Chat.chat.SendMessage(InputBox.Text,Chat.CurrentContact);
|
||||
InputBox.Text = "";
|
||||
}
|
||||
|
||||
internal void ShowMessage(Message message)
|
||||
{
|
||||
if (message.To == User.Me)
|
||||
{
|
||||
App.Current.Dispatcher.Invoke(
|
||||
delegate ()
|
||||
{
|
||||
TextBlock text = new TextBlock
|
||||
{
|
||||
MaxWidth = 400,
|
||||
MinWidth = 10,
|
||||
MinHeight = 30,
|
||||
Text = message.Text,
|
||||
TextWrapping = TextWrapping.Wrap,
|
||||
FontFamily = new FontFamily("Comic Sans MS"),
|
||||
HorizontalAlignment = HorizontalAlignment.Left
|
||||
};
|
||||
Label label = new Label
|
||||
{
|
||||
HorizontalAlignment = HorizontalAlignment.Left,
|
||||
Content = text
|
||||
};
|
||||
OutBox.Children.Add(label);
|
||||
});
|
||||
}//接受到的的消息
|
||||
else
|
||||
{
|
||||
App.Current.Dispatcher.Invoke(
|
||||
delegate ()
|
||||
{
|
||||
|
||||
TextBlock text = new TextBlock
|
||||
{
|
||||
MaxWidth = 400,
|
||||
MinWidth = 10,
|
||||
MinHeight = 30,
|
||||
Text = message.Text,
|
||||
TextWrapping = TextWrapping.Wrap,
|
||||
FontFamily = new FontFamily("Comic Sans MS"),
|
||||
HorizontalAlignment = HorizontalAlignment.Right
|
||||
};
|
||||
Label label = new Label
|
||||
{
|
||||
HorizontalAlignment=HorizontalAlignment.Right,
|
||||
Content=text
|
||||
};
|
||||
OutBox.Children.Add(label);
|
||||
});
|
||||
}//发送的的消息
|
||||
}//将消息展现于UI界面
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user