add role property

This commit is contained in:
NaBian committed 2019-01-29 00:16:09 +08:00
1 parent 8c372510f5
commit 2c0889f64b
24 files changed
+284 -87

No files matched your search

@@ -0,0 +1,83 @@
using System;
using System.IO;
using System.Windows.Input;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.CommandWpf;
using GalaSoft.MvvmLight.Messaging;
using HandyControlDemo.Data;
using Microsoft.Win32;
namespace HandyControlDemo.ViewModel
{
public class ChatBoxViewModel : ViewModelBase
{
private readonly string _id = Guid.NewGuid().ToString();
public ChatBoxViewModel()
{
Messenger.Default.Register<ChatInfoModel>(this, MessageToken.SendChatString, ReceiveString);
Messenger.Default.Register<ChatInfoModel>(this, MessageToken.SendChatImage, ReceiveImage);
Messenger.Default.Register<ChatInfoModel>(this, MessageToken.SendChatAudio, ReceiveAudio);
}
private void ReceiveString(ChatInfoModel info)
{
if (!_id.Equals(info.SenderId)) return;
}
private void ReceiveImage(ChatInfoModel info)
{
if (!_id.Equals(info.SenderId)) return;
}
private void ReceiveAudio(ChatInfoModel info)
{
if (!_id.Equals(info.SenderId)) return;
}
private string _chatString;
public string ChatString
{
get => _chatString;
set => Set(ref _chatString, value);
}
public RelayCommand<KeyEventArgs> SendStringCmd => new Lazy<RelayCommand<KeyEventArgs>>(() =>
new RelayCommand<KeyEventArgs>(SendString)).Value;
private void SendString(KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
if (string.IsNullOrEmpty(ChatString)) return;
Messenger.Default.Send(new ChatInfoModel
{
Message = ChatString,
SenderId = _id
}, MessageToken.SendChatString);
ChatString = string.Empty;
}
}
public RelayCommand OpenImageCmd => new Lazy<RelayCommand>(() =>
new RelayCommand(OpenImage)).Value;
private void OpenImage()
{
var dialog = new OpenFileDialog();
if (dialog.ShowDialog() == true)
{
var fileName = dialog.FileName;
if (File.Exists(fileName))
{
Messenger.Default.Send(new ChatInfoModel
{
Message = fileName,
SenderId = _id
}, MessageToken.SendChatImage);
}
}
}
}
}
@@ -22,6 +22,7 @@ namespace HandyControlDemo.ViewModel
SimpleIoc.Default.Register<ContributorsViewModel>();
SimpleIoc.Default.Register<StepBarDemoViewModel>();
SimpleIoc.Default.Register<PaginationDemoViewModel>();
SimpleIoc.Default.Register<ChatBoxViewModel>();
}
public static ViewModelLocator Instance => new Lazy<ViewModelLocator>(() =>
@@ -45,6 +46,8 @@ namespace HandyControlDemo.ViewModel
public PaginationDemoViewModel PaginationDemo => ServiceLocator.Current.GetInstance<PaginationDemoViewModel>();
public ChatBoxViewModel ChatBox => ServiceLocator.Current.GetInstance<ChatBoxViewModel>();
#endregion
}
}