|
| 1 | +<?xml version="1.0" encoding="utf-8" ?> |
| 2 | +<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" |
| 3 | + xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" |
| 4 | + xmlns:listView="clr-namespace:Syncfusion.Maui.ListView;assembly=Syncfusion.Maui.ListView" |
| 5 | + xmlns:local="clr-namespace:ChatApplication" |
| 6 | + x:Class="ChatApplication.MainPage"> |
| 7 | + |
| 8 | + <ContentPage.BindingContext> |
| 9 | + <local:ViewModel/> |
| 10 | + </ContentPage.BindingContext> |
| 11 | + |
| 12 | + <ContentPage.Resources> |
| 13 | + <ResourceDictionary> |
| 14 | + <DataTemplate x:Key="IncomingMessage"> |
| 15 | + <Grid Padding="10,5"> |
| 16 | + <Grid.ColumnDefinitions> |
| 17 | + <ColumnDefinition Width="Auto"/> |
| 18 | + <ColumnDefinition Width="*"/> |
| 19 | + </Grid.ColumnDefinitions> |
| 20 | + |
| 21 | + <Image WidthRequest="40" HeightRequest="40" HorizontalOptions="Start" |
| 22 | + VerticalOptions="Start" Margin="5" |
| 23 | + Source="{Binding ProfilePicture}"> |
| 24 | + </Image> |
| 25 | + |
| 26 | + <StackLayout Grid.Column="1" Orientation="Vertical" Padding="5,0"> |
| 27 | + <Label Text="{Binding Name}" TextColor="Gray" FontSize="12" |
| 28 | + FontAttributes="Bold" HorizontalOptions="Start"/> |
| 29 | + <Label Text="{Binding Text}" TextColor="Black" BackgroundColor="LightGray" |
| 30 | + Padding="10" MaximumWidthRequest="250" |
| 31 | + HorizontalOptions="StartAndExpand" VerticalOptions="Center"/> |
| 32 | + <Label Text="{Binding Timestamp, StringFormat='{0:HH:mm}'}" |
| 33 | + TextColor="Gray" FontSize="10" HorizontalOptions="Start"/> |
| 34 | + </StackLayout> |
| 35 | + </Grid> |
| 36 | + </DataTemplate> |
| 37 | + |
| 38 | + <DataTemplate x:Key="OutgoingMessage"> |
| 39 | + <Grid Padding="10,5"> |
| 40 | + <Grid.ColumnDefinitions> |
| 41 | + <ColumnDefinition Width="*" /> |
| 42 | + <ColumnDefinition Width="Auto" /> |
| 43 | + <ColumnDefinition Width="Auto"/> |
| 44 | + </Grid.ColumnDefinitions> |
| 45 | + |
| 46 | + <StackLayout Grid.Column="1" Orientation="Vertical" Padding="5,0" |
| 47 | + VerticalOptions="CenterAndExpand"> |
| 48 | + <Label Text="{Binding Name}" TextColor="Gray" FontSize="12" |
| 49 | + FontAttributes="Bold" HorizontalOptions="End" /> |
| 50 | + <Label Text="{Binding Text}" TextColor="White" |
| 51 | + BackgroundColor="DodgerBlue" Padding="10" |
| 52 | + HorizontalOptions="EndAndExpand" VerticalOptions="Center" |
| 53 | + MaximumWidthRequest="250" /> |
| 54 | + <Label Text="{Binding Timestamp, StringFormat='{0:HH:mm}'}" |
| 55 | + TextColor="Gray" FontSize="10" HorizontalOptions="End"/> |
| 56 | + </StackLayout> |
| 57 | + |
| 58 | + <Image Grid.Column="2" WidthRequest="40" HeightRequest="40" Margin="5" |
| 59 | + HorizontalOptions="End" VerticalOptions="Start" |
| 60 | + Source="{Binding ProfilePicture}"> |
| 61 | + </Image> |
| 62 | + </Grid> |
| 63 | + </DataTemplate> |
| 64 | + |
| 65 | + <local:MyDataTemplateSelector x:Key="dataTemplateSelector" |
| 66 | + IncomingDataTemplate="{StaticResource IncomingMessage}" |
| 67 | + OutgoingDataTemplate="{StaticResource OutgoingMessage}"/> |
| 68 | + </ResourceDictionary> |
| 69 | + </ContentPage.Resources> |
| 70 | + |
| 71 | + <listView:SfListView ItemsSource="{Binding Messages}" |
| 72 | + ItemTemplate="{StaticResource dataTemplateSelector}" |
| 73 | + AutoFitMode="Height"> |
| 74 | + </listView:SfListView> |
| 75 | + |
| 76 | +</ContentPage> |
0 commit comments