用户头像显示

This commit is contained in:
Kaniu Tayou
2018-12-25 22:45:58 +08:00
parent 8ec162c5df
commit 96c128b295
13 changed files with 137 additions and 102 deletions
+19 -2
View File
@@ -6,6 +6,7 @@ using System.Threading.Tasks;
using Interact; using Interact;
using System.Drawing; using System.Drawing;
using System.Windows; using System.Windows;
using System.IO;
namespace StormChatWPF namespace StormChatWPF
{ {
@@ -17,7 +18,8 @@ namespace StormChatWPF
{ {
StormClient.OnLoginDone += OnHaveLogin; StormClient.OnLoginDone += OnHaveLogin;
StormClient.OnGetUserListDone += OnGetContactsList; StormClient.OnGetUserListDone += OnGetContactsList;
StormClient.OnMessage +=OnMessage; StormClient.OnMessage +=OnMessage;//事件挂接
User.DefaultPhoto = new MemoryStream(File.ReadAllBytes(@"../../UI/Resources/默认头像.png"));
} }
internal static User CurrentContact { get; set; }//设置当前联系人对象 internal static User CurrentContact { get; set; }//设置当前联系人对象
/// <summary> /// <summary>
@@ -38,7 +40,7 @@ namespace StormChatWPF
mainWindow.Show(); mainWindow.Show();
LogWindow.Instence.Close(); LogWindow.Instence.Close();
}); });
} }//获取联系人列表完成
private void OnHaveLogin(ResultHead head, User user) private void OnHaveLogin(ResultHead head, User user)
{ {
if (head.Error == "") if (head.Error == "")
@@ -48,6 +50,11 @@ namespace StormChatWPF
} }
else else
{ {
App.Current.Dispatcher.Invoke(
(Action)delegate ()
{
LogWindow.Instence.Login_button.IsEnabled = true;
});
MessageBox.Show("请核对账号密码!"); MessageBox.Show("请核对账号密码!");
} }
}//登录完成 }//登录完成
@@ -74,11 +81,21 @@ namespace StormChatWPF
{ {
if (!StormClient.QueueLogin(user, password)) if (!StormClient.QueueLogin(user, password))
{ {
App.Current.Dispatcher.Invoke(
(Action)delegate ()
{
LogWindow.Instence.Login_button.IsEnabled = true;
});
MessageBox.Show("登录失败"); MessageBox.Show("登录失败");
} }
} }
else else
{ {
App.Current.Dispatcher.Invoke(
(Action)delegate ()
{
LogWindow.Instence.Login_button.IsEnabled = true;
});
MessageBox.Show("连接服务器失败!"); MessageBox.Show("连接服务器失败!");
} }
}//登录 }//登录
@@ -29,9 +29,8 @@ namespace StormChatWPF
} }
private void Login_button_Click(object sender, RoutedEventArgs e) private void Login_button_Click(object sender, RoutedEventArgs e)
{ {
Login_button.IsEnabled = false;
Chat.Log(AccountBox.Text,passwordBox.Password); Chat.Log(AccountBox.Text,passwordBox.Password);
} }
} }
} }
@@ -1,4 +1,5 @@
using Interact; using Interact;
using StormChatWPF.UI;
using System; using System;
using System.Linq; using System.Linq;
using System.Windows; using System.Windows;
@@ -58,7 +59,7 @@ namespace StormChatWPF
App.Current.Dispatcher.Invoke( App.Current.Dispatcher.Invoke(
(Action)delegate() (Action)delegate()
{ {
OutBox.Children.Add(new ChatBubble(message,HorizontalAlignment.Left)); OutBox.Children.Add(new StormChatWPF.UI.ChatBubble(message,HorizontalAlignment.Left));
}); });
}//接受到的的消息 }//接受到的的消息
else else
@@ -66,7 +67,7 @@ namespace StormChatWPF
App.Current.Dispatcher.Invoke( App.Current.Dispatcher.Invoke(
(Action)delegate() (Action)delegate()
{ {
OutBox.Children.Add(new ChatBubble(message, HorizontalAlignment.Right)); OutBox.Children.Add(new StormChatWPF.UI.ChatBubble(message, HorizontalAlignment.Right));
}); });
}//发送的的消息 }//发送的的消息
}//将消息展现于UI界面 }//将消息展现于UI界面
@@ -76,7 +77,6 @@ namespace StormChatWPF
App.Current.Dispatcher.Invoke( App.Current.Dispatcher.Invoke(
(Action)delegate () (Action)delegate ()
{ {
OutBox.Children.Add(new HeadPicture());
}); });
} }
} }
@@ -66,7 +66,9 @@
</Compile> </Compile>
<Compile Include="ScrollViewer.cs" /> <Compile Include="ScrollViewer.cs" />
<Compile Include="UI\ChatBubble.cs" /> <Compile Include="UI\ChatBubble.cs" />
<Compile Include="UI\HeadPicture.cs" /> <Compile Include="UI\Contacts.xaml.cs">
<DependentUpon>Contacts.xaml</DependentUpon>
</Compile>
<Compile Include="UI\UserInfo.cs" /> <Compile Include="UI\UserInfo.cs" />
<Compile Include="Window1.xaml.cs"> <Compile Include="Window1.xaml.cs">
<DependentUpon>Window1.xaml</DependentUpon> <DependentUpon>Window1.xaml</DependentUpon>
@@ -87,6 +89,10 @@
<SubType>Designer</SubType> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</Page> </Page>
<Page Include="UI\Contacts.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Window1.xaml"> <Page Include="Window1.xaml">
<SubType>Designer</SubType> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
@@ -129,5 +135,8 @@
<SubType>Designer</SubType> <SubType>Designer</SubType>
</EmbeddedResource> </EmbeddedResource>
</ItemGroup> </ItemGroup>
<ItemGroup>
<Resource Include="UI\Resources\默认头像.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project> </Project>
@@ -5,7 +5,7 @@ using System.Windows.Controls;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
namespace StormChatWPF namespace StormChatWPF.UI
{ {
/// <summary> /// <summary>
/// 聊天气泡 /// 聊天气泡
@@ -0,0 +1,17 @@
<UserControl x:Class="StormChatWPF.UI.Contacts"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:StormChatWPF.UI"
mc:Ignorable="d"
d:DesignHeight="40" d:DesignWidth="120">
<Grid>
<WrapPanel HorizontalAlignment="Left" Height="40" VerticalAlignment="Stretch" Width="120">
<Image x:Name="HeadPicture" HorizontalAlignment="Left" Height="40" Width="40"/>
<Label x:Name="text" Content="Label" Height="40" Width="80"/>
</WrapPanel>
</Grid>
</UserControl>
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace StormChatWPF.UI
{
/// <summary>
/// Contacts.xaml 的交互逻辑
/// </summary>
public partial class Contacts : UserControl
{
public Contacts()
{
InitializeComponent();
}
}
}
@@ -1,32 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows;
using System.Media;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.IO;
namespace StormChatWPF
{
class HeadPicture : Image
{
public HeadPicture(/*Stream imgstream*/)
{
FileStream fileStream = new FileStream(@"C:\Users\Administrator\Desktop\闪电.png", FileMode.Open);
Source = new BitmapImage()
{
StreamSource = fileStream
};
//border.Content = this;
}
private Label border = new Label()
{
};
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 135 KiB

@@ -1,30 +1,20 @@
using Interact; using Interact;
using System; using System.Windows.Media.Imaging;
using System.Collections.Generic; using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows;
namespace StormChatWPF namespace StormChatWPF.UI
{ {
class UserInfo:Label internal class UserInfo : Contacts
{ {
public UserInfo(User user) public UserInfo(User user)
{ {
image.BeginInit();
image.StreamSource = user.Photo;
User.DefaultPhoto.Seek(0, SeekOrigin.Begin);
image.EndInit();
HeadPicture.Source = image;
text.Content = user.NickName;
} }
private Image headpicture = new Image BitmapImage image = new BitmapImage();
{
HorizontalAlignment = HorizontalAlignment.Left
};
private TextBlock UserNmae=new TextBlock
{
FontFamily = new FontFamily("Comic Sans MS"),
HorizontalAlignment = HorizontalAlignment.Right,
VerticalAlignment=VerticalAlignment.Top
};
} }
} }
@@ -7,13 +7,11 @@
mc:Ignorable="d" mc:Ignorable="d"
Title="Window1" Height="300" Width="300"> Title="Window1" Height="300" Width="300">
<Grid> <Grid>
<Label x:Name="label" HorizontalAlignment="Left" Margin="76,101,0,0" VerticalAlignment="Top" Width="86" Height="41"> <StackPanel HorizontalAlignment="Left" Margin="187,0,0,10.4" Width="100">
<Image x:Name="image" Height="31" Width="36" Source="UI/Resources/闪电.png" Margin="0,0,0,0" HorizontalAlignment="Left" RenderTransformOrigin="0.553,0.5" VerticalAlignment="Center"> <Image x:Name="image" Height="46" Source="UI/Resources/聊天气泡.png" Margin="0,0,10,0"/>
<Image.OpacityMask>
<ImageBrush ImageSource="UI/Resources/聊天气泡.png"/> </StackPanel>
</Image.OpacityMask> <Button x:Name="button" Content="Button" HorizontalAlignment="Left" Margin="90,108,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click"/>
</Image>
</Label>
</Grid> </Grid>
</Window> </Window>
@@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Windows; using System.Windows;
@@ -22,5 +23,14 @@ namespace StormChatWPF
{ {
InitializeComponent(); InitializeComponent();
} }
private void Button_Click(object sender, RoutedEventArgs e)
{
image.Source = new BitmapImage()
{
StreamSource = new FileStream(@"C:\Users\10568\Source\Repos\stormchat\stormchat-client-csharp\StormChatWPF\UI\Resources\闪电.png", FileMode.Open)
};
}
} }
} }