WPF仿微信界面发送消息简易版

WPF仿微信界面发送消息简易版

参考别的博主的例子用WPF MVVM框架来仿了一个微信聊天界面,做了个发送消息简易功能,下面一起来看看吧!

以下为View视图布局代码,消息对话框的样式直接在这里定义了,主要定义的是用户头像、对话框和发送时间的样式,其中设置了文字消息自动换行。

<Window x:Class="DEMO.View.ChatWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:DEMO.View"
        xmlns:custom="clr-namespace:DEMO.VO"
        mc:Ignorable="d" Title="ChatWindow" 
        Height="600" Width="410" 
        ResizeMode="NoResize" WindowStartupLocation="CenterScreen"
        WindowStyle="None" Background="Transparent" 
        DataContext="{Binding Source={StaticResource Locator},Path=Chat}"
        AllowsTransparency="True">
    <Window.Resources>
        <ResourceDictionary>
            <!--发送的信息-->
            <DataTemplate x:Key="chatSend1">
                <StackPanel x:Name="SendMsg" Orientation="Horizontal" Margin="0,12,20,0" HorizontalAlignment="Right">
                    <StackPanel Orientation="Vertical" Margin="0,0,10,0">
                        <StackPanel Orientation="Horizontal">
                            <!--名称-->
                            <TextBlock Text="{Binding UserName}" Foreground="#999" Margin="2,0,0,3" HorizontalAlignment="Right" FontSize="10"/>
                            <!--时间-->
                            <TextBlock Text="{Binding MessageTime}" Foreground="#999" Margin="8,0,0,3" HorizontalAlignment="Right" FontSize="10"/>
                        </StackPanel>
                        <!--消息内容-->
                        <Border Background="#c8dd1f" BorderThickness="1" BorderBrush="#ddd" CornerRadius="8,0,8,8" MinHeight="30" MinWidth="50" MaxWidth="200">
                            <TextBox IsReadOnly="True" Background="Transparent" BorderThickness="0" TextWrapping="Wrap" Text="{Binding SendMessage}" FontSize="14" Margin="8" VerticalAlignment="Center"/>
                        </Border>
                    </StackPanel>
                    <!--头像-->
                    <Bord
  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值