This commit is contained in:
lxmou666 2021-02-17 10:38:11 +08:00
parent eccc26c6c4
commit ba5f72c73e
3 changed files with 78 additions and 1 deletions

View File

@ -19,6 +19,7 @@ namespace JianGongYun.TRTC.ViewModels
{
public event PropertyChangedEventHandler PropertyChanged;
#region
/// <summary>
/// 教室信息
/// </summary>
@ -317,6 +318,7 @@ namespace JianGongYun.TRTC.ViewModels
}
}
}
#endregion
#region
public Style MainBigWrapStyle
@ -350,5 +352,27 @@ namespace JianGongYun.TRTC.ViewModels
}
#endregion
#region
/// <summary>
/// 消息集合
/// </summary>
private ObservableCollection<string> _Chats = new ObservableCollection<string>() { "1", "2" };
public ObservableCollection<string> Chats
{
set
{
_Chats = value;
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs("Chats"));//对StudentCount进行监听
}
}
get
{
return _Chats;
}
}
#endregion
}
}

View File

@ -14,7 +14,41 @@
MouseDown="Window_MouseDown"
Title="" Height="600" Width="200">
<Window.Resources>
<Style x:Key="placeHolder" TargetType="{x:Type TextBox}" BasedOn="{StaticResource {x:Type TextBox}}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TextBox}">
<Grid>
<TextBox Padding="14,0,14,0" VerticalContentAlignment="Center" Text="{Binding Path=Text,
RelativeSource={RelativeSource TemplatedParent},
Mode=TwoWay,
UpdateSourceTrigger=PropertyChanged}"
x:Name="textSource"
Background="Transparent"
Foreground="White"
Panel.ZIndex="2" />
<TextBox Padding="14,0,14,0" VerticalContentAlignment="Center" Text="{TemplateBinding Tag}" Background="{TemplateBinding Background}" Panel.ZIndex="1">
<TextBox.Style>
<Style TargetType="{x:Type TextBox}">
<Setter Property="Foreground" Value="Transparent"/>
<Style.Triggers>
<DataTrigger Binding="{Binding Path=Text, Source={x:Reference textSource}}" Value="">
<Setter Property="Foreground" Value="#fff"/>
</DataTrigger>
</Style.Triggers>
</Style>
</TextBox.Style>
</TextBox>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<BooleanToVisibilityConverter x:Key="VisibilityOfBool" />
<!--自定义ListBox项样式-->
<DataTemplate x:Key="cusItem">
<TextBlock Foreground="White" Text="{Binding}"></TextBlock>
</DataTemplate>
</Window.Resources>
<DockPanel>
<!--预览框-->
@ -24,11 +58,19 @@
<TextBlock Foreground="White" FontSize="13" HorizontalAlignment="Center" VerticalAlignment="Center">摄像头未开启</TextBlock>
</Grid>
<Grid Visibility="{Binding CameraRunning, Converter={StaticResource VisibilityOfBool}}" x:Name="PreVideoWrap" Background="#202020" Width="{Binding ElementName=PreViewWrap,Path=ActualWidth}" Height="{Binding ElementName=PreViewWrap,Path=ActualHeight}" Canvas.Top="0" Canvas.Left="0"></Grid>
</Canvas>
</Grid>
<!--聊天版面-->
<Grid Background="#33000000">
<DockPanel>
<!--输入框-->
<DockPanel DockPanel.Dock="Bottom" Height="30">
<TextBox Background="Transparent" Foreground="White" Style="{StaticResource placeHolder}" PreviewKeyDown="TextBox_PreviewKeyDown" Tag="输入"></TextBox>
</DockPanel>
<!--消息列表-->
<ListBox ItemTemplate="{StaticResource cusItem}" ItemsSource="{Binding Chats}" Background="Transparent"></ListBox>
</DockPanel>
</Grid>
</DockPanel>
</Window>

View File

@ -84,5 +84,16 @@ namespace JianGongYun.TRTC.Windows
}
}
private void TextBox_PreviewKeyDown(object sender, KeyEventArgs e)
{
//输入框回车
if (e.Key == Key.Enter)
{
var text = (TextBox)sender;
//socket.send(text.Text);
LiveWindow.LiveWindowViewModel.Chats.Add(text.Text);//往Chats集合添加数据会自动更新到界面上
text.Text = "";
}
}
}
}