Skip to content

Commit e8568d9

Browse files
committed
Prepared chat application sample
1 parent dee45db commit e8568d9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+9196
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.12.35521.163 d17.12
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ChatApplication", "ChatApplication\ChatApplication.csproj", "{6BE82A5A-80DD-4553-A26D-FF454EB100EE}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{6BE82A5A-80DD-4553-A26D-FF454EB100EE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{6BE82A5A-80DD-4553-A26D-FF454EB100EE}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{6BE82A5A-80DD-4553-A26D-FF454EB100EE}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{6BE82A5A-80DD-4553-A26D-FF454EB100EE}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version = "1.0" encoding = "UTF-8" ?>
2+
<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
xmlns:local="clr-namespace:ChatApplication"
5+
x:Class="ChatApplication.App">
6+
<Application.Resources>
7+
<ResourceDictionary>
8+
<ResourceDictionary.MergedDictionaries>
9+
<ResourceDictionary Source="Resources/Styles/Colors.xaml" />
10+
<ResourceDictionary Source="Resources/Styles/Styles.xaml" />
11+
</ResourceDictionary.MergedDictionaries>
12+
</ResourceDictionary>
13+
</Application.Resources>
14+
</Application>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace ChatApplication
2+
{
3+
public partial class App : Application
4+
{
5+
public App()
6+
{
7+
InitializeComponent();
8+
}
9+
10+
protected override Window CreateWindow(IActivationState? activationState)
11+
{
12+
return new Window(new AppShell());
13+
}
14+
}
15+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<Shell
3+
x:Class="ChatApplication.AppShell"
4+
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
5+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
6+
xmlns:local="clr-namespace:ChatApplication"
7+
Shell.FlyoutBehavior="Flyout"
8+
Title="ChatApplication">
9+
10+
<ShellContent
11+
ContentTemplate="{DataTemplate local:MainPage}"
12+
Route="MainPage" />
13+
14+
</Shell>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace ChatApplication
2+
{
3+
public partial class AppShell : Shell
4+
{
5+
public AppShell()
6+
{
7+
InitializeComponent();
8+
}
9+
}
10+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFrameworks>net9.0-android;net9.0-ios;net9.0-maccatalyst</TargetFrameworks>
5+
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net9.0-windows10.0.19041.0</TargetFrameworks>
6+
<!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET -->
7+
<!-- <TargetFrameworks>$(TargetFrameworks);net9.0-tizen</TargetFrameworks> -->
8+
9+
<!-- Note for MacCatalyst:
10+
The default runtime is maccatalyst-x64, except in Release config, in which case the default is maccatalyst-x64;maccatalyst-arm64.
11+
When specifying both architectures, use the plural <RuntimeIdentifiers> instead of the singular <RuntimeIdentifier>.
12+
The Mac App Store will NOT accept apps with ONLY maccatalyst-arm64 indicated;
13+
either BOTH runtimes must be indicated or ONLY macatalyst-x64. -->
14+
<!-- For example: <RuntimeIdentifiers>maccatalyst-x64;maccatalyst-arm64</RuntimeIdentifiers> -->
15+
16+
<OutputType>Exe</OutputType>
17+
<RootNamespace>ChatApplication</RootNamespace>
18+
<UseMaui>true</UseMaui>
19+
<SingleProject>true</SingleProject>
20+
<ImplicitUsings>enable</ImplicitUsings>
21+
<Nullable>enable</Nullable>
22+
23+
<!-- Display name -->
24+
<ApplicationTitle>ChatApplication</ApplicationTitle>
25+
26+
<!-- App Identifier -->
27+
<ApplicationId>com.companyname.chatapplication</ApplicationId>
28+
29+
<!-- Versions -->
30+
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
31+
<ApplicationVersion>1</ApplicationVersion>
32+
33+
<!-- To develop, package, and publish an app to the Microsoft Store, see: https://aka.ms/MauiTemplateUnpackaged -->
34+
<WindowsPackageType>None</WindowsPackageType>
35+
36+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">15.0</SupportedOSPlatformVersion>
37+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">15.0</SupportedOSPlatformVersion>
38+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>
39+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>
40+
<TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
41+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
42+
</PropertyGroup>
43+
44+
<ItemGroup>
45+
<!-- App Icon -->
46+
<MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4" />
47+
48+
<!-- Splash Screen -->
49+
<MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#512BD4" BaseSize="128,128" />
50+
51+
<!-- Images -->
52+
<MauiImage Include="Resources\Images\*" />
53+
<MauiImage Update="Resources\Images\dotnet_bot.png" Resize="True" BaseSize="300,185" />
54+
55+
<!-- Custom Fonts -->
56+
<MauiFont Include="Resources\Fonts\*" />
57+
58+
<!-- Raw Assets (also remove the "Resources\Raw" prefix) -->
59+
<MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
60+
</ItemGroup>
61+
62+
<ItemGroup>
63+
<PackageReference Include="Microsoft.Maui.Controls" Version="9.0.21" />
64+
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="9.0.0" />
65+
<PackageReference Include="Syncfusion.Maui.ListView" Version="*" />
66+
</ItemGroup>
67+
68+
</Project>
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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>
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using System.Collections.ObjectModel;
2+
3+
namespace ChatApplication
4+
{
5+
public partial class MainPage : ContentPage
6+
{
7+
public MainPage()
8+
{
9+
InitializeComponent();
10+
}
11+
}
12+
13+
public class Message
14+
{
15+
public string? Name { get; set; }
16+
public string? Text { get; set; }
17+
public bool IsIncoming { get; set; }
18+
public string? ProfilePicture { get; set; }
19+
public DateTime Timestamp { get; set; }
20+
}
21+
22+
public class ViewModel
23+
{
24+
public ObservableCollection<Message> Messages { get; set; }
25+
26+
public ViewModel()
27+
{
28+
Messages = new ObservableCollection<Message>
29+
{
30+
new Message { Name = "You", Text = "Hi everyone! I'm very excited to share the news that our team is launching a new mobile application.", IsIncoming = false, ProfilePicture = "andrea.png", Timestamp = DateTime.Now.AddMinutes(-2)},
31+
new Message { Name = "Harrison", Text = "Oh, that's great!", IsIncoming = true, ProfilePicture = "harrison.png", Timestamp = DateTime.Now.AddMinutes(-1)},
32+
new Message { Name = "Margaret", Text = "That is a good news.", IsIncoming = true, ProfilePicture = "margaret.png", Timestamp = DateTime.Now.AddMinutes(2)},
33+
new Message { Name = "Nancy", Text = "Are we going to develop the app natively or as a hybrid?", IsIncoming = true, ProfilePicture = "nancy.png", Timestamp = DateTime.Now.AddMinutes(3)},
34+
new Message { Name = "You", Text = "We should develop this app using .NET MAUI, as it offers a native experience and performance while allowing for seamless cross-platform development.", IsIncoming = false, ProfilePicture = "andrea.png", Timestamp = DateTime.Now.AddMinutes(5)},
35+
new Message { Name = "Steven", Text = "I haven't heard of .NET MAUI. What's .NET MAUI?", IsIncoming = true, ProfilePicture = "steven.png", Timestamp = DateTime.Now.AddMinutes(7)},
36+
new Message { Name = "You", Text = ".NET MAUI is a new library that allows you to build native user interfaces for Android, iOS, macOS, and Windows from a single shared C# codebase.", IsIncoming = false, ProfilePicture = "andrea.png", Timestamp = DateTime.Now.AddMinutes(9)},
37+
new Message { Name = "David", Text = "That's impressive.", IsIncoming = true, ProfilePicture = "david.png", Timestamp = DateTime.Now.AddMinutes(10)},
38+
};
39+
}
40+
}
41+
42+
public class MyDataTemplateSelector : DataTemplateSelector
43+
{
44+
public DataTemplate? IncomingDataTemplate { get; set; }
45+
public DataTemplate? OutgoingDataTemplate { get; set; }
46+
protected override DataTemplate OnSelectTemplate(object item, BindableObject container)
47+
{
48+
if (item is Message message)
49+
{
50+
return message.IsIncoming ? IncomingDataTemplate : OutgoingDataTemplate;
51+
}
52+
53+
return null;
54+
}
55+
}
56+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using Microsoft.Extensions.Logging;
2+
using Syncfusion.Maui.Core.Hosting;
3+
4+
namespace ChatApplication
5+
{
6+
public static class MauiProgram
7+
{
8+
public static MauiApp CreateMauiApp()
9+
{
10+
var builder = MauiApp.CreateBuilder();
11+
builder
12+
.UseMauiApp<App>()
13+
.ConfigureSyncfusionCore()
14+
.ConfigureFonts(fonts =>
15+
{
16+
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
17+
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
18+
});
19+
20+
#if DEBUG
21+
builder.Logging.AddDebug();
22+
#endif
23+
24+
return builder.Build();
25+
}
26+
}
27+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
3+
<application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true"></application>
4+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
5+
<uses-permission android:name="android.permission.INTERNET" />
6+
</manifest>

0 commit comments

Comments
 (0)