forked from xiaoyaocz/biliuwp-lite
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
555 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
175 changes: 175 additions & 0 deletions
175
src/BiliLite.UWP/Controls/ChatMessages/ChatMessageTemplate.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
<ResourceDictionary | ||
x:Class="BiliLite.Controls.ChatMessages.ChatMessageTemplate" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:dataTemplateSelectors="using:BiliLite.Controls.DataTemplateSelectors" | ||
xmlns:msg="using:BiliLite.Models.Common.Msg" | ||
xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls"> | ||
<dataTemplateSelectors:ChatMessageDataTemplateSelector x:Key="ChatMessageDataTemplateSelector" | ||
NotificationTemplate="{StaticResource ChatMessageNotification}" | ||
ImageTemplate="{StaticResource ChatMessageImage}" | ||
TextTemplate="{StaticResource ChatMessageText}" | ||
OtherTemplate="{StaticResource ChatMessageOther}"> | ||
</dataTemplateSelectors:ChatMessageDataTemplateSelector> | ||
|
||
<DataTemplate x:Key="ChatMessageText" x:DataType="msg:ChatMessage"> | ||
<Grid Margin="0 8"> | ||
<Grid Visibility="{Binding IsSelf,Converter={StaticResource display}}" Margin="10"> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition Width="Auto"/> | ||
<ColumnDefinition Width="*"/> | ||
</Grid.ColumnDefinitions> | ||
<Ellipse Width="40" Height="40" Margin="10,0,10,0" | ||
VerticalAlignment="Top"> | ||
<Ellipse.Fill> | ||
<ImageBrush ImageSource="{Binding Path=Face,Mode=OneWay,Converter={StaticResource imageConvert2},ConverterParameter='42w'}"></ImageBrush> | ||
</Ellipse.Fill> | ||
</Ellipse> | ||
|
||
<!--消息气泡--> | ||
<Border Background="{ThemeResource DefaultCardColor}" | ||
Grid.Column="1" | ||
CornerRadius="10" Padding="10" > | ||
<StackPanel> | ||
<TextBlock Text="{Binding TextContent.Content}" TextWrapping="Wrap"/> | ||
</StackPanel> | ||
</Border> | ||
</Grid> | ||
|
||
<Grid Visibility="{Binding IsSelf}" Margin="10"> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition Width="*"/> | ||
<ColumnDefinition Width="Auto"/> | ||
</Grid.ColumnDefinitions> | ||
<Ellipse Grid.Column="1" Width="40" Height="40" Margin="10,0,10,0" | ||
VerticalAlignment="Top"> | ||
<Ellipse.Fill> | ||
<ImageBrush ImageSource="{Binding Path=Face,Mode=OneWay,Converter={StaticResource imageConvert2},ConverterParameter='42w'}"></ImageBrush> | ||
</Ellipse.Fill> | ||
</Ellipse> | ||
|
||
<!--消息气泡--> | ||
<Border Background="{ThemeResource DefaultCardColor}" | ||
CornerRadius="10" Padding="10" > | ||
<StackPanel HorizontalAlignment="Right"> | ||
<TextBlock Text="{Binding TextContent.Content}" TextWrapping="Wrap"/> | ||
</StackPanel> | ||
</Border> | ||
</Grid> | ||
</Grid> | ||
</DataTemplate> | ||
|
||
<DataTemplate x:Key="ChatMessageImage" x:DataType="msg:ChatMessage"> | ||
<Grid Margin="0 8"> | ||
<Grid Visibility="{Binding IsSelf,Converter={StaticResource display}}" Margin="10"> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition Width="Auto"/> | ||
<ColumnDefinition Width="*"/> | ||
</Grid.ColumnDefinitions> | ||
<Ellipse Width="40" Height="40" Margin="10,0,10,0" | ||
VerticalAlignment="Top"> | ||
<Ellipse.Fill> | ||
<ImageBrush ImageSource="{Binding Path=Face,Mode=OneWay,Converter={StaticResource imageConvert2},ConverterParameter='42w'}"></ImageBrush> | ||
</Ellipse.Fill> | ||
</Ellipse> | ||
|
||
<!--消息气泡--> | ||
<Border Background="{ThemeResource DefaultCardColor}" | ||
Grid.Column="1" | ||
CornerRadius="10" Padding="10" > | ||
<StackPanel> | ||
<HyperlinkButton Padding="0" | ||
Click="OpenImageBtn_OnClick"> | ||
<controls:ImageEx | ||
IsCacheEnabled="True" | ||
PlaceholderSource="ms-appx:///Assets/Thumbnails/Placeholde.png" | ||
MaxHeight="150" | ||
MaxWidth="300" | ||
Source="{Binding ImageContent.Url}" ></controls:ImageEx> | ||
</HyperlinkButton> | ||
</StackPanel> | ||
</Border> | ||
</Grid> | ||
|
||
<Grid Visibility="{Binding IsSelf}" Margin="10"> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition Width="*"/> | ||
<ColumnDefinition Width="Auto"/> | ||
</Grid.ColumnDefinitions> | ||
<Ellipse Grid.Column="1" Width="40" Height="40" Margin="10,0,10,0" | ||
VerticalAlignment="Top"> | ||
<Ellipse.Fill> | ||
<ImageBrush ImageSource="{Binding Path=Face,Mode=OneWay,Converter={StaticResource imageConvert2},ConverterParameter='42w'}"></ImageBrush> | ||
</Ellipse.Fill> | ||
</Ellipse> | ||
|
||
<!--消息气泡--> | ||
<Border Background="{ThemeResource DefaultCardColor}" | ||
CornerRadius="10" Padding="10" > | ||
<StackPanel HorizontalAlignment="Right"> | ||
<HyperlinkButton Padding="0" | ||
Click="OpenImageBtn_OnClick"> | ||
<controls:ImageEx | ||
IsCacheEnabled="True" | ||
PlaceholderSource="ms-appx:///Assets/Thumbnails/Placeholde.png" | ||
MaxHeight="150" | ||
MaxWidth="300" | ||
Source="{Binding ImageContent.Url}" ></controls:ImageEx> | ||
</HyperlinkButton> | ||
</StackPanel> | ||
</Border> | ||
</Grid> | ||
</Grid> | ||
</DataTemplate> | ||
|
||
<DataTemplate x:Key="ChatMessageNotification" x:DataType="msg:ChatMessage"> | ||
<Grid Background="{ThemeResource DefaultCardColor}" Padding="16" CornerRadius="8" BorderThickness="1" BorderBrush="LightGray" | ||
MaxWidth="480" | ||
Margin="0 16"> | ||
<Grid.RowDefinitions> | ||
<RowDefinition Height="Auto"/> | ||
<RowDefinition Height="Auto"/> | ||
<RowDefinition Height="*"/> | ||
<RowDefinition Height="Auto"/> | ||
</Grid.RowDefinitions> | ||
|
||
<!-- 标题 --> | ||
<TextBlock x:Name="TitleText" Text="{Binding NotificationContent.Title}" FontSize="18" FontWeight="Bold" Grid.Row="0" Margin="0,0,0,8"/> | ||
|
||
<!-- 详情文本 --> | ||
<TextBlock x:Name="DetailText" Text="{Binding NotificationContent.Text}" FontSize="14" Grid.Row="1" Margin="0,0,0,16" | ||
TextWrapping="Wrap"/> | ||
|
||
<!-- 信息表格 --> | ||
<ItemsControl x:Name="InfoItemsControl" Grid.Row="2" Margin="0,0,0,16" ItemsSource="{Binding NotificationContent.Modules}"> | ||
<ItemsControl.ItemTemplate> | ||
<DataTemplate> | ||
<Grid> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition Width="Auto"/> | ||
<ColumnDefinition Width="*"/> | ||
</Grid.ColumnDefinitions> | ||
<TextBlock Text="{Binding Title}" FontSize="14" Margin="0,0,8,4"/> | ||
<TextBlock Text="{Binding Detail}" FontSize="14" Grid.Column="1" Margin="0,0,0,4"/> | ||
</Grid> | ||
</DataTemplate> | ||
</ItemsControl.ItemTemplate> | ||
</ItemsControl> | ||
|
||
<!-- 操作按钮 --> | ||
<StackPanel Orientation="Horizontal" Grid.Row="3" HorizontalAlignment="Right"> | ||
<Button Content="{Binding NotificationContent.JumpText}" Visibility="{Binding NotificationContent.ShowJumpBtn}" Click="NotificationMsgAction_OnClick" /> | ||
<Button Content="{Binding NotificationContent.JumpText2}" Visibility="{Binding NotificationContent.ShowJumpBtn2}" Click="NotificationMsgAction_OnClick" /> | ||
<Button Content="{Binding NotificationContent.JumpText3}" Visibility="{Binding NotificationContent.ShowJumpBtn3}" Click="NotificationMsgAction_OnClick" /> | ||
</StackPanel> | ||
</Grid> | ||
</DataTemplate> | ||
|
||
<DataTemplate x:Key="ChatMessageOther"> | ||
<Border BorderThickness="1" HorizontalAlignment="Stretch" BorderBrush="#C8E5E9EF" CornerRadius="4"> | ||
<StackPanel Margin="12"> | ||
<TextBlock TextWrapping="Wrap">暂不支持的消息格式</TextBlock> | ||
</StackPanel> | ||
</Border> | ||
</DataTemplate> | ||
</ResourceDictionary> |
18 changes: 18 additions & 0 deletions
18
src/BiliLite.UWP/Controls/ChatMessages/ChatMessageTemplate.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System; | ||
using Windows.UI.Xaml; | ||
|
||
namespace BiliLite.Controls.ChatMessages | ||
{ | ||
public partial class ChatMessageTemplate : ResourceDictionary | ||
{ | ||
private void NotificationMsgAction_OnClick(object sender, RoutedEventArgs e) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
private void OpenImageBtn_OnClick(object sender, RoutedEventArgs e) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/BiliLite.UWP/Controls/DataTemplateSelectors/ChatMessageDataTemplateSelector.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Windows.UI.Xaml.Controls; | ||
using Windows.UI.Xaml; | ||
using BiliLite.Models.Common.Msg; | ||
|
||
namespace BiliLite.Controls.DataTemplateSelectors | ||
{ | ||
public class ChatMessageDataTemplateSelector : DataTemplateSelector | ||
{ | ||
private static readonly Dictionary<ChatMsgType, Func<ChatMessageDataTemplateSelector, ChatMessage, DataTemplate>> _chatMsgTypeTemplateSelectFuncs; | ||
|
||
static ChatMessageDataTemplateSelector() | ||
{ | ||
_chatMsgTypeTemplateSelectFuncs = | ||
new Dictionary<ChatMsgType, Func<ChatMessageDataTemplateSelector, | ||
ChatMessage, DataTemplate>>() | ||
{ | ||
{ ChatMsgType.Text, (selector, chatMessage) => selector.TextTemplate }, | ||
{ ChatMsgType.Image, (selector, chatMessage) => selector.ImageTemplate }, | ||
{ ChatMsgType.CustomEmote, (selector, chatMessage) => selector.ImageTemplate }, | ||
{ ChatMsgType.Notification, (selector, chatMessage) => selector.NotificationTemplate }, | ||
}; | ||
} | ||
|
||
public DataTemplate TextTemplate { get; set; } | ||
|
||
public DataTemplate ImageTemplate { get; set; } | ||
|
||
public DataTemplate NotificationTemplate { get; set; } | ||
|
||
public DataTemplate OtherTemplate { get; set; } | ||
|
||
protected override DataTemplate SelectTemplateCore(object item, DependencyObject container) | ||
{ | ||
var chatMessage = item as ChatMessage; | ||
var success = _chatMsgTypeTemplateSelectFuncs.TryGetValue(chatMessage.MsgType, out var selectFunc); | ||
return success ? selectFunc(this, chatMessage) : OtherTemplate; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.