diff --git a/HandyControl/Controls/Input/SearchBar.cs b/HandyControl/Controls/Input/SearchBar.cs
index d37ab5b1..6243b3c8 100644
--- a/HandyControl/Controls/Input/SearchBar.cs
+++ b/HandyControl/Controls/Input/SearchBar.cs
@@ -39,6 +39,7 @@ namespace HandyControl.Controls
if (_textBox != null)
{
_textBox.TextChanged -= TextBox_TextChanged;
+ _textBox.KeyDown -= TextBox_KeyDown;
}
base.OnApplyTemplate();
diff --git a/HandyControl/Controls/Other/ChatBubble.cs b/HandyControl/Controls/Other/ChatBubble.cs
index 497897d0..1ef28aa1 100644
--- a/HandyControl/Controls/Other/ChatBubble.cs
+++ b/HandyControl/Controls/Other/ChatBubble.cs
@@ -1,14 +1,18 @@
-using System.Windows.Controls;
+using System.Windows;
+using System.Windows.Controls;
+using HandyControl.Data;
namespace HandyControl.Controls
{
public class ChatBubble : ContentControl
{
+ public static readonly DependencyProperty RoleProperty = DependencyProperty.Register(
+ "Role", typeof(ChatRoleType), typeof(ChatBubble), new PropertyMetadata(default(ChatRoleType)));
-
- //public ChatBubble(object message)
- //{
-
- //}
+ public ChatRoleType Role
+ {
+ get => (ChatRoleType) GetValue(RoleProperty);
+ set => SetValue(RoleProperty, value);
+ }
}
}
\ No newline at end of file
diff --git a/HandyControl/Data/Enum/ChatRoleType.cs b/HandyControl/Data/Enum/ChatRoleType.cs
new file mode 100644
index 00000000..e9fadbfe
--- /dev/null
+++ b/HandyControl/Data/Enum/ChatRoleType.cs
@@ -0,0 +1,8 @@
+namespace HandyControl.Data
+{
+ public enum ChatRoleType
+ {
+ Sender,
+ Receiver
+ }
+}
\ No newline at end of file
diff --git a/HandyControl/HandyControl.csproj b/HandyControl/HandyControl.csproj
index 01dcb6c7..24c5dc99 100644
--- a/HandyControl/HandyControl.csproj
+++ b/HandyControl/HandyControl.csproj
@@ -157,6 +157,7 @@
+
diff --git a/HandyControl/Themes/Styles/Base/ChatBubbleBaseStyle.xaml b/HandyControl/Themes/Styles/Base/ChatBubbleBaseStyle.xaml
index 217d9b96..8b9853f7 100644
--- a/HandyControl/Themes/Styles/Base/ChatBubbleBaseStyle.xaml
+++ b/HandyControl/Themes/Styles/Base/ChatBubbleBaseStyle.xaml
@@ -7,23 +7,62 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/HandyControlDemo/Data/MessageToken.cs b/HandyControlDemo/Data/MessageToken.cs
index ff8d59f7..5cebeecb 100644
--- a/HandyControlDemo/Data/MessageToken.cs
+++ b/HandyControlDemo/Data/MessageToken.cs
@@ -138,12 +138,19 @@
public static readonly string CustomNonClientAreaWindow = nameof(CustomNonClientAreaWindow);
- public static readonly string LoadShowContent = nameof(LoadShowContent);
+ public static readonly string LoadShowContent = nameof(LoadShowContent);
- public static readonly string FullSwitch = nameof(FullSwitch);
+ public static readonly string FullSwitch = nameof(FullSwitch);
- public static readonly string ContributorsView = nameof(ContributorsView);
+ public static readonly string ContributorsView = nameof(ContributorsView);
- public static readonly string ClearLeftSelected = nameof(ClearLeftSelected);
- }
+ public static readonly string ClearLeftSelected = nameof(ClearLeftSelected);
+
+ public static readonly string SendChatString = nameof(SendChatString);
+
+ public static readonly string SendChatImage = nameof(SendChatImage);
+
+ public static readonly string SendChatAudio = nameof(SendChatAudio);
+
+ }
}
\ No newline at end of file
diff --git a/HandyControlDemo/Data/MessageToken.tt b/HandyControlDemo/Data/MessageToken.tt
index 4fcd0b93..7155e49d 100644
--- a/HandyControlDemo/Data/MessageToken.tt
+++ b/HandyControlDemo/Data/MessageToken.tt
@@ -79,6 +79,16 @@ var windowList = new List
"CommonWindow",
"CustomNonClientAreaWindow"
};
+var messageList = new List
+{
+ "LoadShowContent",
+ "FullSwitch",
+ "ContributorsView",
+ "ClearLeftSelected",
+ "SendChatString",
+ "SendChatImage",
+ "SendChatAudio"
+};
#>
namespace HandyControlDemo.Data
{
@@ -96,12 +106,9 @@ namespace HandyControlDemo.Data
public static readonly string <#=item#> = nameof(<#=item#>);
<#}#>
- public static readonly string LoadShowContent = nameof(LoadShowContent);
+<#foreach(var item in messageList){#>
+ public static readonly string <#=item#> = nameof(<#=item#>);
- public static readonly string FullSwitch = nameof(FullSwitch);
-
- public static readonly string ContributorsView = nameof(ContributorsView);
-
- public static readonly string ClearLeftSelected = nameof(ClearLeftSelected);
- }
+ <#}#>
+}
}
\ No newline at end of file
diff --git a/HandyControlDemo/Data/Model/ChatInfoModel.cs b/HandyControlDemo/Data/Model/ChatInfoModel.cs
new file mode 100644
index 00000000..9e3b795f
--- /dev/null
+++ b/HandyControlDemo/Data/Model/ChatInfoModel.cs
@@ -0,0 +1,9 @@
+namespace HandyControlDemo.Data
+{
+ public class ChatInfoModel
+ {
+ public string Message { get; set; }
+
+ public string SenderId { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/HandyControlDemo/HandyControlDemo.csproj b/HandyControlDemo/HandyControlDemo.csproj
index 77747122..a26d040d 100644
--- a/HandyControlDemo/HandyControlDemo.csproj
+++ b/HandyControlDemo/HandyControlDemo.csproj
@@ -103,6 +103,7 @@
True
MessageToken.tt
+
@@ -123,6 +124,9 @@
Avatar.xaml
+
+ ChatBox.xaml
+
AnimationPathDemoCtl.xaml
@@ -327,15 +331,16 @@
TreeViewDemoCtl.xaml
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
-
+
AboutWindow.xaml
@@ -411,6 +416,10 @@
Designer
MSBuild:Compile
+
+ Designer
+ MSBuild:Compile
+
Designer
MSBuild:Compile
@@ -725,6 +734,8 @@
TextTemplatingFileGenerator
MessageToken.cs
+
+
diff --git a/HandyControlDemo/Resources/Img/Chat/chat_back1.jpg b/HandyControlDemo/Resources/Img/Chat/chat_back1.jpg
new file mode 100644
index 00000000..45672774
Binary files /dev/null and b/HandyControlDemo/Resources/Img/Chat/chat_back1.jpg differ
diff --git a/HandyControlDemo/Resources/Img/Chat/chat_back2.jpg b/HandyControlDemo/Resources/Img/Chat/chat_back2.jpg
new file mode 100644
index 00000000..f7120af2
Binary files /dev/null and b/HandyControlDemo/Resources/Img/Chat/chat_back2.jpg differ
diff --git a/HandyControlDemo/UserControl/Basic/ChatBox.xaml b/HandyControlDemo/UserControl/Basic/ChatBox.xaml
new file mode 100644
index 00000000..a9c78463
--- /dev/null
+++ b/HandyControlDemo/UserControl/Basic/ChatBox.xaml
@@ -0,0 +1,48 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/HandyControlDemo/UserControl/Basic/ChatBox.xaml.cs b/HandyControlDemo/UserControl/Basic/ChatBox.xaml.cs
new file mode 100644
index 00000000..affe29d0
--- /dev/null
+++ b/HandyControlDemo/UserControl/Basic/ChatBox.xaml.cs
@@ -0,0 +1,10 @@
+namespace HandyControlDemo.UserControl
+{
+ public partial class ChatBox
+ {
+ public ChatBox()
+ {
+ InitializeComponent();
+ }
+ }
+}
diff --git a/HandyControlDemo/UserControl/Controls/ChatBubbleDemoCtl.xaml b/HandyControlDemo/UserControl/Controls/ChatBubbleDemoCtl.xaml
index 78ba80ab..b9b99343 100644
--- a/HandyControlDemo/UserControl/Controls/ChatBubbleDemoCtl.xaml
+++ b/HandyControlDemo/UserControl/Controls/ChatBubbleDemoCtl.xaml
@@ -1,54 +1,20 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/HandyControlDemo/ViewModel/Basic/ChatBoxViewModel.cs b/HandyControlDemo/ViewModel/Basic/ChatBoxViewModel.cs
new file mode 100644
index 00000000..65314d57
--- /dev/null
+++ b/HandyControlDemo/ViewModel/Basic/ChatBoxViewModel.cs
@@ -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(this, MessageToken.SendChatString, ReceiveString);
+ Messenger.Default.Register(this, MessageToken.SendChatImage, ReceiveImage);
+ Messenger.Default.Register(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 SendStringCmd => new Lazy>(() =>
+ new RelayCommand(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(() =>
+ 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);
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/HandyControlDemo/ViewModel/ComboBoxDemoViewModel.cs b/HandyControlDemo/ViewModel/Common/ComboBoxDemoViewModel.cs
similarity index 100%
rename from HandyControlDemo/ViewModel/ComboBoxDemoViewModel.cs
rename to HandyControlDemo/ViewModel/Common/ComboBoxDemoViewModel.cs
diff --git a/HandyControlDemo/ViewModel/GrowlDemoViewModel.cs b/HandyControlDemo/ViewModel/Controls/GrowlDemoViewModel.cs
similarity index 100%
rename from HandyControlDemo/ViewModel/GrowlDemoViewModel.cs
rename to HandyControlDemo/ViewModel/Controls/GrowlDemoViewModel.cs
diff --git a/HandyControlDemo/ViewModel/ImageBrowserDemoViewModel.cs b/HandyControlDemo/ViewModel/Controls/ImageBrowserDemoViewModel.cs
similarity index 100%
rename from HandyControlDemo/ViewModel/ImageBrowserDemoViewModel.cs
rename to HandyControlDemo/ViewModel/Controls/ImageBrowserDemoViewModel.cs
diff --git a/HandyControlDemo/ViewModel/PaginationDemoViewModel.cs b/HandyControlDemo/ViewModel/Controls/PaginationDemoViewModel.cs
similarity index 100%
rename from HandyControlDemo/ViewModel/PaginationDemoViewModel.cs
rename to HandyControlDemo/ViewModel/Controls/PaginationDemoViewModel.cs
diff --git a/HandyControlDemo/ViewModel/StepBarDemoViewModel.cs b/HandyControlDemo/ViewModel/Controls/StepBarDemoViewModel.cs
similarity index 100%
rename from HandyControlDemo/ViewModel/StepBarDemoViewModel.cs
rename to HandyControlDemo/ViewModel/Controls/StepBarDemoViewModel.cs
diff --git a/HandyControlDemo/ViewModel/WindowDemoViewModel.cs b/HandyControlDemo/ViewModel/Controls/WindowDemoViewModel.cs
similarity index 100%
rename from HandyControlDemo/ViewModel/WindowDemoViewModel.cs
rename to HandyControlDemo/ViewModel/Controls/WindowDemoViewModel.cs
diff --git a/HandyControlDemo/ViewModel/ContributorsViewModel.cs b/HandyControlDemo/ViewModel/Main/ContributorsViewModel.cs
similarity index 100%
rename from HandyControlDemo/ViewModel/ContributorsViewModel.cs
rename to HandyControlDemo/ViewModel/Main/ContributorsViewModel.cs
diff --git a/HandyControlDemo/ViewModel/MainViewModel.cs b/HandyControlDemo/ViewModel/Main/MainViewModel.cs
similarity index 100%
rename from HandyControlDemo/ViewModel/MainViewModel.cs
rename to HandyControlDemo/ViewModel/Main/MainViewModel.cs
diff --git a/HandyControlDemo/ViewModel/ViewModelLocator.cs b/HandyControlDemo/ViewModel/ViewModelLocator.cs
index 9e7d5c0e..cda8e343 100644
--- a/HandyControlDemo/ViewModel/ViewModelLocator.cs
+++ b/HandyControlDemo/ViewModel/ViewModelLocator.cs
@@ -22,6 +22,7 @@ namespace HandyControlDemo.ViewModel
SimpleIoc.Default.Register();
SimpleIoc.Default.Register();
SimpleIoc.Default.Register();
+ SimpleIoc.Default.Register();
}
public static ViewModelLocator Instance => new Lazy(() =>
@@ -45,6 +46,8 @@ namespace HandyControlDemo.ViewModel
public PaginationDemoViewModel PaginationDemo => ServiceLocator.Current.GetInstance();
+ public ChatBoxViewModel ChatBox => ServiceLocator.Current.GetInstance();
+
#endregion
}
}
\ No newline at end of file