Contents:

Free Python Course ➞ Mini-course for beginners and experienced coders. 4 cool projects in the portfolio, live communication with the speaker. Click and find out what you can learn in the course.
Learn moreIn this series of articles, we will develop a client-server application in C# – a simple messenger. This series consists of three parts, in which we will cover in detail the stages of application creation, from architectural design to the implementation of messaging functionality. We'll focus on key aspects such as networking, data processing, and the user interface, allowing you to master the fundamentals of instant messaging development on the C# platform.
- Application coding — we'll create a graphical interface in C# and XAML for Windows.
- WebAPI creation in ASP.NET — we'll create a database and develop the server side of the application.
- Integrating the client and server — we'll write requests to the server and ensure everything works as expected.
The C# programming language is a versatile tool for developing a variety of applications. Using WPF, a platform for creating graphical interfaces, you can develop aesthetically pleasing and functional applications for the Windows operating system. ASP.NET, in turn, provides the capabilities for developing high-performance server applications, making C# an ideal choice for web development. Using C# opens up broad horizons for creating both client-side and server-side solutions, providing flexibility and power in software development.
In this text, I will try to explain the key aspects in detail, but please note that it is impossible to cover every nuance. Therefore, it is important to have a basic knowledge of C#, object-oriented programming (OOP), ASP.NET, WPF, and Visual Studio. This knowledge will help you better understand the topics discussed and successfully apply them in practice.
We recommend reading a number of articles that will help you understand the issues you are interested in. These materials contain useful information and may answer your questions.
- OOP in C# (article series).
- How to create a website in ASP.NET in an hour.
- What is MVVM: designing applications for Windows.
- Asynchronous programming: How the processor works (article series).
Application structure
We don't focus on aspects like registration, contact search, message storage, or complex design. Instead, we'll teach you the basics of developing client-server applications, allowing you to implement the entire application creation process yourself.
You can find the source code of the messenger on the GitHub platform.
The application will be structured into several screens for the convenience of users. Each screen is designed to perform specific functions and provides an intuitive interface. This will allow users to easily navigate the application and quickly find the tools they need. Each screen will be optimized for the best user experience, which will increase the efficiency of interaction with the application.
- authorization screen;
- contacts screen;
- chat screen.
The screen is a Border element that is hidden from the user by default. It becomes visible only when active, allowing the user to focus on important information.
On the authorization screen, the user is given the opportunity to enter their username and password to log in. If the data is entered correctly, the user will be redirected to the contacts screen. In case of an incorrect entry, an error message will appear informing you of the need to try again.
The contacts screen displays the names of the users with whom you are chatting. The chat opens when you click on the name of the selected user, allowing you to conveniently continue the conversation.
The chat screen displays the conversation with the selected contact. The user can send a new message or return to the contact list to select another interlocutor.
Layout of the authorization screen
Let's start with defining styles. In this section, we will briefly outline the appearance of the elements and immediately indicate that screens should be hidden by default. This will ensure optimal page loading and improve the user experience. Hiding screens will avoid visual clutter and focus on the key interface elements.
Now let's create a authorization screen that will be clearly visible to users. It is necessary to pay attention to its design and functionality to ensure a simple and intuitive login process. Interface elements should be logically arranged, and data entry fields should be large enough for ease of use. It's also important to add clear tooltips and error messages so users can easily navigate the authorization process. Proper authorization screen layout will not only improve user experience but also increase conversion on the site.
Let's look at how this is represented.

Let's create an event handler for pressing the Enter button. This handler will allow the user to perform data entry actions when pressing the Enter key. It will track the key press and call the appropriate function, providing interactivity and ease of use when working with forms or interface elements. This will improve the user experience and make interaction with the application more intuitive. Note the need to add a check to ensure that the handler is only triggered when the Enter key is pressed, preventing unwanted actions when pressing other keys.
For the Open() method to function correctly, screens named ContactsScreen and ChatScreen must exist. Create two empty Border elements to provide functionality for these screens.
The login screen displays an error message when invalid data is entered. The user is prompted to try entering their credentials again. It's important that the interface is intuitive and that the messages clearly communicate the problem. An effective login screen design helps avoid confusion and improves the user experience. Please pay attention to the correct design of input fields and buttons to make the authorization process simple and convenient.

Let's create a page with contact information. On this screen, users will be able to find the necessary contact information, including address, phone number, and email. Contacts will be presented in a convenient format to ensure easy access to information. This will help improve customer interactions and enhance service levels.
Layout of the contact screen
The contact screen will be divided into two rows using Grid. The first row contains the header, and the second contains the contact list. The contact list is presented as a ListBox element, which displays all the necessary contact information.
This section does not provide a complete list of elements, but only a template that will be used when binding data. This template will be useful in the final version of the application, but to simplify the layout process, we recommend preparing test data. This will allow you to effectively test the functionality and visual perception of the interface.
Styles play a key role in web design, as they determine the appearance and perception of the site. Correct application of styles allows you to not only improve visual appeal but also enhance usability. Using CSS (Cascading Style Sheets) allows developers to easily change the appearance of elements such as fonts, colors, margins, and sizes. Styles help create a unique feel for a website and maintain its identity.
It's important to remember that optimized styles contribute to faster page load times, which has a positive impact on SEO. Well-structured and minimalist styles reduce website response times, which also impacts search engine rankings. Furthermore, responsive styles allow a website to display correctly on various devices, an important factor in modern web design.
Effective use of styles not only improves user experience but also helps improve website visibility in search engines, which ultimately leads to increased traffic. Therefore, it's important to pay attention to both the design and technical aspects of styles to achieve the best results.
Now we need to develop a method for opening a chat with the selected contact. This method will be activated when the user makes a selection from the list.
Layout of the Chat Screen
Chat is an interface that resembles the contacts screen, but includes additional functionality. It allows users to not only browse their contact list but also conduct active conversations in real time. Convenient tools for exchanging messages, sending media files, and creating group chats make communication more interactive and effective. This approach promotes closer interaction between users and improves the overall communication experience.

Grid divides the screen into three main sections: header, chat, and input field. The header displays the name of the interlocutor and the Back button. The chat is presented as a ListBox, which shows the message history. At the bottom of the screen there is a text input field and a button for sending messages. This structure provides a user-friendly and intuitive interface.
This contact screen does not yet contain any data; it only provides a template for displaying it. Some styles have been applied to enhance the visual appearance.
Event handling for the buttons responsible for submitting data and navigation needs to be implemented. This will allow the user to interact with the interface more effectively. Event handling involves adding appropriate listeners that will respond to button clicks, ensuring the associated actions are executed correctly. Ensure all features work smoothly to improve user experience and increase efficiency of working with the application.

