Listview完整显示用户头像及昵称信息

This commit is contained in:
Kaniu Tayou
2018-12-27 17:42:26 +08:00
parent 96c128b295
commit 688a53a9dd
6 changed files with 126 additions and 119 deletions
@@ -19,7 +19,8 @@
<ColumnDefinition Width="200*"/>
<ColumnDefinition Width="200*"/>
</Grid.ColumnDefinitions>
<ListView x:Name="UsersList" Margin="0,0,0,0" IsEnabled="True" SelectionChanged="UsersList_SelectionChanged" Grid.Row="1" Grid.RowSpan="2"/>
<ListView x:Name="UsersList" Margin="0,0,0,0" IsEnabled="True" SelectionChanged="UsersList_SelectionChanged" Grid.Row="1" Grid.RowSpan="2">
</ListView>
<TextBox x:Name="InputBox" Margin="0,0,0,0" TextWrapping="Wrap" Text="" Grid.Row="2" Grid.ColumnSpan="3" Grid.Column="1" />
<Button Content="Send" HorizontalAlignment="Right" Margin="0,0,0,0" VerticalAlignment="Bottom" Width="75" Click="Button_Click" Height="20" Grid.Row="2" Grid.Column="3"/>
<ScrollViewer Grid.ColumnSpan="3" Grid.Column="1" Margin="0,0,0,0" Grid.Row="1" >
@@ -27,6 +28,6 @@
<StackPanel x:Name="OutBox" Margin="0,0,0,0" Grid.ColumnSpan="3" Grid.Column="1" Grid.Row="1" ScrollViewer.VerticalScrollBarVisibility="Hidden"/>
</ScrollViewer.Content>
</ScrollViewer>
<Button x:Name="button" Content="Button" Grid.Column="2" HorizontalAlignment="Left" Margin="73,31,0,0" Grid.Row="2" VerticalAlignment="Top" Width="75" Click="button_Click_1"/>
<Button x:Name="button" Content="更改头像" Grid.Column="1" HorizontalAlignment="Left" Margin="0,64,0,-2" Grid.Row="2" VerticalAlignment="Top" Width="75" Click="button_Click_1"/>
</Grid>
</Window>
@@ -25,7 +25,13 @@ namespace StormChatWPF
{
foreach (var user in Chat.ContactsList)
{
UsersList.Items.Add(user.NickName);
if (user.Name !=User.Me.Name)
{
UsersList.Items.Add(new UI.ContactsInfo(user)
{
HorizontalAlignment = HorizontalAlignment.Center
});
}
}
}
}//向联系人列表listview中添加元素
@@ -45,7 +51,7 @@ namespace StormChatWPF
MessageBox.Show("请选择联系人!");
return;
}
if (InputBox.Text!="")
if (InputBox.Text != "")
{
Chat.chat.SendMessage(InputBox.Text, Chat.CurrentContact);
InputBox.Text = "";
@@ -57,15 +63,15 @@ namespace StormChatWPF
if (message.To == User.Me)
{
App.Current.Dispatcher.Invoke(
(Action)delegate()
(Action)delegate ()
{
OutBox.Children.Add(new StormChatWPF.UI.ChatBubble(message,HorizontalAlignment.Left));
OutBox.Children.Add(new StormChatWPF.UI.ChatBubble(message, HorizontalAlignment.Left));
});
}//接受到的的消息
else
{
App.Current.Dispatcher.Invoke(
(Action)delegate()
(Action)delegate ()
{
OutBox.Children.Add(new StormChatWPF.UI.ChatBubble(message, HorizontalAlignment.Right));
});
@@ -69,7 +69,7 @@
<Compile Include="UI\Contacts.xaml.cs">
<DependentUpon>Contacts.xaml</DependentUpon>
</Compile>
<Compile Include="UI\UserInfo.cs" />
<Compile Include="UI\ContactsInfo.cs" />
<Compile Include="Window1.xaml.cs">
<DependentUpon>Window1.xaml</DependentUpon>
</Compile>
@@ -5,11 +5,11 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:StormChatWPF.UI"
mc:Ignorable="d"
d:DesignHeight="40" d:DesignWidth="120">
d:DesignHeight="40" d:DesignWidth="120" HorizontalAlignment="Stretch">
<Grid>
<WrapPanel HorizontalAlignment="Left" Height="40" VerticalAlignment="Stretch" Width="120">
<WrapPanel Height="40" VerticalAlignment="Stretch">
<Image x:Name="HeadPicture" HorizontalAlignment="Left" Height="40" Width="40"/>
<Label x:Name="text" Content="Label" Height="40" Width="80"/>
<Label x:Name="text" Content="Label" Height="40" FontSize="14" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" HorizontalAlignment="Center"/>
</WrapPanel>
@@ -4,9 +4,9 @@ using System.IO;
namespace StormChatWPF.UI
{
internal class UserInfo : Contacts
internal class ContactsInfo : Contacts
{
public UserInfo(User user)
public ContactsInfo(User user)
{
image.BeginInit();
image.StreamSource = user.Photo;