UWP Development, Modify UserListViewModel ViewModel

UWP (Universal Windows Platform) is a platform that allows the development of apps that can run on various Windows devices. UWP apps typically use the MVVM (Model-View-ViewModel) design pattern to separate the UI and business logic. In this article, we will explore how to modify the UserListViewModel of a UWP app to add functionality. This example demonstrates how to manage a user list using basic data binding and command patterns.

Understanding the MVVM Pattern

The MVVM pattern is very important in UWP app development. This pattern consists of three main components:

  • Model: Contains the data and business logic of the application.
  • View: Composes the user interface (UI) and is the part that the user sees.
  • ViewModel: Acts as an intermediary between the View and Model, providing the necessary data and commands to the View.

UserListViewModel is a ViewModel that represents and manages the user list. This ViewModel manages the user list data with ObservableCollection, automatically reflecting changes in this collection to the View.

Understanding the Structure of UserListViewModel

By default, UserListViewModel can perform the functions of retrieving and filtering the list of users. Below is the basic structure of UserListViewModel:

csharp
public class UserListViewModel : INotifyPropertyChanged
{
    private ObservableCollection _users;
    public ObservableCollection Users
    {
        get { return _users; }
        set
        {
            _users = value;
            OnPropertyChanged(nameof(Users));
        }
    }
    
    public UserListViewModel()
    {
        Users = new ObservableCollection();
        LoadUsers();
    }

    private void LoadUsers()
    {
        // Load users here.
    }

    public event PropertyChangedEventHandler PropertyChanged;
    protected void OnPropertyChanged(string propertyName)
    {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }
}

Adding Functionality to UserListViewModel

Let’s add search and filtering functionality to this user list ViewModel. This will allow users to search the list by user names. To do this, we can add the following properties and methods.

csharp
private string _searchTerm;
public string SearchTerm
{
    get { return _searchTerm; }
    set
    {
        _searchTerm = value;
        OnPropertyChanged(nameof(SearchTerm));
        FilterUsers();
    }
}

private void FilterUsers()
{
    // Add the logic to filter the user list here.
}

Now we can implement the logic to filter the Users collection based on the user’s name in the FilterUsers() method.

csharp
private void FilterUsers()
{
    var filteredUsers = Users.Where(user => user.Name.Contains(SearchTerm, StringComparison.OrdinalIgnoreCase)).ToList();
    
    Users.Clear();
    foreach (var user in filteredUsers)
    {
        Users.Add(user);
    }
}

Data Binding with the UI

Now let’s connect UserListViewModel to the UI. In UWP’s XAML, you can easily bind ViewModel properties to the UI through data binding. First, you need to set the data context in the XAML file.

xml

    
    
        
    

    
        
        
            
                
                    
                
            
        
    

Data and Custom Objects

The User class should contain user information. Below is the basic structure of the User class.

csharp
public class User
{
    public string Name { get; set; }
}

Complete Example

Let’s put all the code together to complete the example. Below is a complete implementation of UserListViewModel and an example of a XAML page.

csharp
public class User
{
    public string Name { get; set; }
}

public class UserListViewModel : INotifyPropertyChanged
{
    private ObservableCollection _users;
    public ObservableCollection Users
    {
        get { return _users; }
        set
        {
            _users = value;
            OnPropertyChanged(nameof(Users));
        }
    }
    
    private string _searchTerm;
    public string SearchTerm
    {
        get { return _searchTerm; }
        set
        {
            _searchTerm = value;
            OnPropertyChanged(nameof(SearchTerm));
            FilterUsers();
        }
    }

    public UserListViewModel()
    {
        Users = new ObservableCollection();
        LoadUsers();
    }

    private void LoadUsers()
    {
        // Add sample data for the user list
        Users.Add(new User { Name = "Alice" });
        Users.Add(new User { Name = "Bob" });
        Users.Add(new User { Name = "Charlie" });
    }

    private void FilterUsers()
    {
        var filteredUsers = Users.Where(user => user.Name.Contains(SearchTerm, StringComparison.OrdinalIgnoreCase)).ToList();
        
        Users.Clear();
        foreach (var user in filteredUsers)
        {
            Users.Add(user);
        }
    }

    public event PropertyChangedEventHandler PropertyChanged;
    protected void OnPropertyChanged(string propertyName)
    {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }
}
xml

    
    
        
    

    
        
        
            
                
                    
                
            
        
    

Conclusion

In this article, we discussed how to modify UserListViewModel in UWP development to add filtering functionality. We demonstrated how to efficiently manage a user list using data binding with the MVVM pattern. This structural approach greatly helps enhance code reusability and maintainability in UWP app development.

As you continue UWP development, I encourage you to learn more patterns and techniques and apply them to develop better apps.

UWP Development, Modifying UserListPage View

Hello! In this post, we will take a detailed look at Universal Windows Platform (UWP) development. In particular, I will explain how to modify the view of the UserListPage. UWP is a platform that supports app development for a variety of Windows 10 devices and consists of various user interface (UI) elements. In this lesson, we will learn how to display a list of users using XAML and C# and improve the interaction with the view.

1. Introduction to UWP

UWP is a platform created by Microsoft that supports the development of apps that run on various Windows devices, including desktops, tablets, Xbox, and IoT devices. UWP apps are composed of a UI that uses XAML and backend logic that uses C# or C++. This structure allows developers to create applications optimized for a wide range of screen sizes and resolutions.

1.1 Features of UWP

  • Responsive Design: UWP provides the ability to automatically support various screen sizes and resolutions.
  • Security: It runs in a sandboxed environment, ensuring the safe protection of user data.
  • Zero Page (App Bar): It supports easy access for users through essential elements in the UI.

2. Overview of UserListPage

The UserListPage is an important component of a UWP application that displays a list of users. It usually shows the user’s profile picture, name, status, etc., and interactions with users are often important.

2.1 Basic ViewModel Setup

The data needed to build the user list is passed through the ViewModel. UserViewModel represents the data of each user and contains specific properties.


public class UserViewModel
{
    public string UserName { get; set; }
    public string UserStatus { get; set; }
    public string UserImage { get; set; }

    public UserViewModel(string userName, string userStatus, string userImage)
    {
        UserName = userName;
        UserStatus = userStatus;
        UserImage = userImage;
    }
}

3. Modifying the UserListPage View

By modifying the view of the UserListPage, we can provide a more useful and intuitive user experience. Here, we will use GridView to dynamically display the list of users and add click events to each user item to show additional information.

3.1 Setting Up XAML Structure

We will use GridView in XAML to display the list of users. We can define the display format and style for each user item.




    
        
            
                
                    
                        
                        
                        
                    
                
            
        
    

3.2 Adding Backend Logic

Now, let’s implement the backend logic for the UserListPage and connect the ViewModel that manages the user list. We will write a LoadUsers method to load the initial user list.


// UserListPage.xaml.cs
public sealed partial class UserListPage : Page
{
    public ObservableCollection Users { get; set; }

    public UserListPage()
    {
        this.InitializeComponent();
        Users = new ObservableCollection();
        LoadUsers();
        UserGridView.ItemsSource = Users;
    }

    private void LoadUsers()
    {
        Users.Add(new UserViewModel("Alice", "Online", "Assets/alice.png"));
        Users.Add(new UserViewModel("Bob", "Offline", "Assets/bob.png"));
        Users.Add(new UserViewModel("Charlie", "Away", "Assets/charlie.png"));
        // Add other users
    }

    private void UserGridView_ItemClick(object sender, ItemClickEventArgs e)
    {
        UserViewModel user = e.ClickedItem as UserViewModel;
        Frame.Navigate(typeof(UserDetailPage), user);
    }
}

4. Improving User Interface

To enhance the UI, we can add various visual elements. For example, we can change the color based on the user’s status or add animations to UI elements to enhance responsiveness and visual appeal.

4.1 Displaying Colors Based on Status

We will add logic to change the background color based on the user’s status. For example, we can set Green for online users, Red for offline users, and Yellow for away users.


private void LoadUsers()
{
    Users.Add(new UserViewModel("Alice", "Online", "Assets/alice.png"));
    Users.Add(new UserViewModel("Bob", "Offline", "Assets/bob.png"));
    Users.Add(new UserViewModel("Charlie", "Away", "Assets/charlie.png"));
}

private SolidColorBrush GetStatusColor(string userStatus)
{
    switch (userStatus)
    {
        case "Online":
            return new SolidColorBrush(Colors.Green);
        case "Offline":
            return new SolidColorBrush(Colors.Red);
        case "Away":
            return new SolidColorBrush(Colors.Yellow);
        default:
            return new SolidColorBrush(Colors.Gray);
    }
}

4.2 Applying Status Colors in XAML

In XAML, we can use a Converter to represent status colors in the DataTemplate. This part can directly be implemented in XAML, so let’s check the modification points in the code.



    
        
        
        
    

5. Testing and Debugging

After development is complete, it is essential to perform testing and debugging. In addition to verifying the click event on the user list and the correct display of the list, you must check responsiveness on various screen sizes.

5.1 Writing Unit Tests

It is advisable to write unit tests to ensure that the user list functionality remains intact when code changes. This allows testing of the loading and responsiveness of the user list.


[TestMethod]
public void TestLoadUsers()
{
    var page = new UserListPage();
    page.LoadUsers();
    
    Assert.AreEqual(3, page.Users.Count);
    Assert.AreEqual("Alice", page.Users[0].UserName);
}

5.2 Exception Handling

Handling potential exceptions in the code will enhance the user experience. For example, we need to implement a way to display an exception message to the user if failing to load user information due to network issues.


try
{
    LoadUsers();
}
catch (Exception ex)
{
    // Log the exception or notify the user.
}

6. Conclusion

In this post, we learned how to modify the view of UserListPage in UWP. By leveraging XAML and C#, we were able to create a dynamic user list and improve the UI and interactions, enhancing the user experience.

The UWP platform is attractive due to its easy-to-use APIs and various features, holding many possibilities for the future. Keep learning and experimenting to implement your desired features. Welcome to the world of UWP development!

7. Additional Resources

If you would like additional resources on this topic, please refer to the links below:

8. Questions and Discussions

If you have any questions or comments about the blog post, please leave them in the comments. If you need further assistance or more in-depth information, feel free to contact us anytime. Thank you!

UWP Development, Modifying UserDetailViewModel ViewModel

UWP (Universal Windows Platform) development is an essential element in creating applications that can run on various modern platforms. In this post, we will detail the method of modifying UserDetailViewModel, which is an important part of UWP application development, focusing on the MVVM (Model-View-ViewModel) architecture. Throughout this process, we will explain the significance and usage of the MVVM pattern, and we will practice with specific code examples.

1. Understanding the MVVM Pattern

The MVVM pattern is an architectural pattern that separates the application’s configuration to improve maintainability and reusability. MVVM consists of three components:

  • Model: Manages the application’s data and business logic.
  • View: Composes the user interface (UI) and allows users to interact with the Model through events.
  • ViewModel: Mediates the interaction between the View and the Model. It primarily includes logic related to data binding, commands, and event handling.

2. Introduction to UserDetailViewModel in UWP Applications

UserDetailViewModel is the ViewModel responsible for displaying and editing details of a specific user. It contains properties that can bind user information (e.g., name, email, phone number, etc.) to the UI and commands for modifying that information.

By implementing UserDetailViewModel in UWP applications, users can conveniently manage their information through the UI. This ViewModel should include the following key features:

  • Loading and saving user information
  • Detecting and reflecting changes in user information
  • Supporting data binding with the UI

3. Basic Structure of UserDetailViewModel

Here, we will look at the basic structure of a simple UserDetailViewModel. Below is the basic code written in C#:

using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows.Input;

public class UserDetailViewModel : INotifyPropertyChanged
{
    private string _name;
    private string _email;
    private string _phoneNumber;

    public string Name
    {
        get { return _name; }
        set { SetProperty(ref _name, value); }
    }

    public string Email
    {
        get { return _email; }
        set { SetProperty(ref _email, value); }
    }

    public string PhoneNumber
    {
        get { return _phoneNumber; }
        set { SetProperty(ref _phoneNumber, value); }
    }

    public ICommand SaveCommand { get; private set; }

    public UserDetailViewModel()
    {
        SaveCommand = new RelayCommand(Save);
    }

    private void Save()
    {
        // Implement save logic
        // e.g., Save user information to database
    }

    public event PropertyChangedEventHandler PropertyChanged;

    protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
    {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }

    protected bool SetProperty(ref T storage, T value, [CallerMemberName] string propertyName = null)
    {
        if (Equals(storage, value)) return false;
        storage = value;
        OnPropertyChanged(propertyName);
        return true;
    }
}

4. Implementing Data Binding in ViewModel

In UWP, binding data in the ViewModel is essential. The above UserDetailViewModel implements the INotifyPropertyChanged interface to automatically reflect property value changes in the UI.

You can set up binding with the View in the XAML file as follows:

<Page.DataContext>
    <local:UserDetailViewModel />
</Page.DataContext>

<StackPanel>
    <TextBox Text="{Binding Name, Mode=TwoWay}" />
    <TextBox Text="{Binding Email, Mode=TwoWay}" />
    <TextBox Text="{Binding PhoneNumber, Mode=TwoWay}" />
    <Button Content="Save" Command="{Binding SaveCommand}" />
</StackPanel>

In the above code, each TextBox is bound to the properties of the ViewModel, updating the properties automatically whenever the user inputs information. This reduces code duplication and maximizes the separation between UI and business logic.

5. Expanding UserDetailViewModel Features

Now, let’s add additional features to UserDetailViewModel. For example, we can implement a feature to validate user information.

private string _errorMessage;
public string ErrorMessage
{
    get { return _errorMessage; }
    set { SetProperty(ref _errorMessage, value); }
}

private bool ValidateInputs()
{
    if (string.IsNullOrWhiteSpace(Name))
    {
        ErrorMessage = "Name is required.";
        return false;
    }
    // Implement additional validation
    return true;
}

private void Save()
{
    if (!ValidateInputs())
    {
        // Do not save if validation fails
        return;
    }
    
    // Implement save logic
}

Now, when the user attempts to save their information, the input will be validated first, and if there are issues, an error message will be provided. This helps improve the user experience.

6. Integrating with Data Storage

It is also crucial to integrate UserDetailViewModel with the actual data storage. Here, we will demonstrate a simple example using LocalStorage for data storage.

private async void LoadUserData()
{
    // Asynchronous method to load user data
    var userData = await LoadDataFromStorageAsync();
    Name = userData.Name;
    Email = userData.Email;
    PhoneNumber = userData.PhoneNumber;
}

private async Task LoadDataFromStorageAsync()
{
    // Implement asynchronous data retrieval
}

private async Task SaveDataToStorageAsync()
{
    // Implement asynchronous data saving
}

private void Save()
{
    if (!ValidateInputs())
    {
        return;
    }

    await SaveDataToStorageAsync();
}

In the code above, the LoadUserData method asynchronously loads user data, and the SaveDataToStorageAsync method saves the modified user information.

7. Verifying Functionality

Now that all implementations are complete, we will build and run the UWP application to check if all the written code works as expected. Users can enter information through the UI and use the “Save” button to save their information.

8. Conclusion

In this post, we learned how to modify UserDetailViewModel in UWP applications. By realizing a clear separation between the view, viewmodel, and model through the MVVM pattern, we were able to enhance maintainability and reusability. Additionally, through validation and integration with the data storage, we confirmed the operation in a real application.

We will continue to cover more information on UWP development, so please stay tuned!

UWP Development, Adding UserDetail Page

UWP (Universal Windows Platform) app development is the process of creating applications that can run on various Windows devices. In this tutorial, we will explain in detail how to add a ‘UserDetail’ page to a UWP app. This page displays user details and contains features aimed at enhancing the app’s usability.

1. Overview of UWP and UserDetail Page

UWP is an app platform based on the Windows 10 operating system. With UWP, you can develop applications that can be used on various devices, including desktops, tablets, and console TVs. The UserDetail page shows the user’s profile information and has become one of the essential elements of the application.

2. Setting Up the Development Environment

To develop UWP apps, the following development environment is required:

  • Windows 10 Operating System: UWP development is supported only on Windows 10.
  • Visual Studio 2022: An IDE for developing UWP applications.
  • Windows SDK: The SDK necessary for UWP development.

3. Creating a UWP Project

First, open Visual Studio and create a new UWP project. Follow the steps below:

  1. Launch Visual Studio.
  2. Select File > New > Project.
  3. Select ‘Blank App (Universal Windows)’ and specify a project name, then click the ‘Create’ button.
  4. Select the Target version and Minimum version. It is recommended to set it to the latest version.

4. Adding UserDetail Page

Now it’s time to add the ‘UserDetail’ page to the project. Please follow these steps:

  1. Right-click the project in Solution Explorer and select ‘Add’ > ‘New Item.’
  2. Select ‘Blank Page’ and name the page ‘UserDetailPage.xaml.’

4.1 Designing UserDetailPage.xaml

Design the UI of the added page. Below is example code for UserDetailPage.xaml:

<Page
    x:Class="YourAppNamespace.UserDetailPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:YourAppNamespace"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <StackPanel Margin="20">
            <TextBlock Text="User Detail" FontSize="30" FontWeight="Bold" Margin="0,0,0,20"/>
            <TextBlock Text="Name:" FontSize="20" FontWeight="SemiBold"/>
            <TextBlock x:Name="UserName" FontSize="20" Margin="0,0,0,10"/>
            <TextBlock Text="Email:" FontSize="20" FontWeight="SemiBold"/>
            <TextBlock x:Name="UserEmail" FontSize="20" Margin="0,0,0,10"/>
            <Button Content="Edit" Click="EditButton_Click" Width="100" Height="40"/>
        </StackPanel>
    </Grid>
</Page>

4.2 Writing Code in UserDetailPage.xaml.cs

To define the behavior of the page, write the UserDetailPage.xaml.cs file as follows. Here, we implement the function of selecting and displaying basic user information from a list.

using Windows.UI.Xaml.Controls;

namespace YourAppNamespace
{
    public sealed partial class UserDetailPage : Page
    {
        public UserDetailPage()
        {
            this.InitializeComponent();
            LoadUserData();
        }

        private void LoadUserData()
        {
            // Sample data - can be replaced with actual database calls
            UserName.Text = "John Doe";
            UserEmail.Text = "johndoe@example.com";
        }

        private void EditButton_Click(object sender, RoutedEventArgs e)
        {
            // Implement edit functionality
            // For example: navigate to the user detail edit page
        }
    }
}

5. Setting Up Navigation

Set up navigation to allow the UserDetail page to be called from other pages. You can navigate to the UserDetail page through button click events on the main page or list page.

private void UserListView_ItemClick(object sender, ItemClickEventArgs e)
{
    Frame.Navigate(typeof(UserDetailPage), e.ClickedItem);
}

6. Data Binding and Applying MVVM Pattern

In UWP development, you can manage data binding using the MVVM (Model-View-ViewModel) pattern. Below is an example implementing MVVM:

public class UserViewModel : INotifyPropertyChanged
{
    private string _userName;
    public string UserName
    {
        get => _userName;
        set
        {
            _userName = value;
            OnPropertyChanged();
        }
    }

    private string _userEmail;
    public string UserEmail
    {
        get => _userEmail;
        set
        {
            _userEmail = value;
            OnPropertyChanged();
        }
    }

    public void LoadUserData()
    {
        // Sample data - can be replaced with actual database calls
        UserName = "John Doe";
        UserEmail = "johndoe@example.com";
    }

    public event PropertyChangedEventHandler PropertyChanged;
    protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
    {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }
}

6.1 Applying MVVM in UserDetailPage.xaml

Now, set up data binding using the above ViewModel in UserDetailPage.xaml:

<Page.DataContext>
    <local:UserViewModel />
</Page.DataContext>

<TextBlock Text="{Binding UserName}" FontSize="20" Margin="0,0,0,10"/>
<TextBlock Text="{Binding UserEmail}" FontSize="20" Margin="0,0,0,10"/>

7. Saving and Loading Data

We will discuss how to save and retrieve information entered by the user. UWP can use local databases or files to store data. Below is a simple example of saving and loading using files:

private async void SaveUserData()
{
    var file = await Windows.Storage.KnownFolders.DocumentsLibrary.CreateFileAsync("UserData.txt", Windows.Storage.CreationCollisionOption.ReplaceExisting);
    await Windows.Storage.FileIO.WriteLinesAsync(file, new List { UserName.Text, UserEmail.Text });
}

private async void LoadUserData()
{
    try
    {
        var file = await Windows.Storage.KnownFolders.DocumentsLibrary.GetFileAsync("UserData.txt");
        var lines = await Windows.Storage.FileIO.ReadLinesAsync(file);
        UserName.Text = lines[0];
        UserEmail.Text = lines[1];
    }
    catch (FileNotFoundException)
    {
        // Set default values if the file is not found
        UserName.Text = "John Doe";
        UserEmail.Text = "johndoe@example.com";
    }
}

8. Testing and Debugging

Once development is complete, run the app in Visual Studio to verify that the UserDetail page works as expected. The following points should be tested:

  • Ensure the UserDetail page displays correctly.
  • Check if user information loads properly.
  • Verify that the functionality works correctly when the edit button is clicked.

9. Conclusion

This document provides a detailed explanation of how to add a UserDetail page to a UWP app. By leveraging the powerful features of UWP, you can create applications that can be used across various devices. We hope you have learned the structure and operating principle of a basic UserDetail page through this tutorial. We wish you much success in your future UWP development journey.

10. References

UWP Development, Modifying UserDetailPage View

UWP (Universal Windows Platform) development is a powerful platform that allows you to create applications that can run on various Windows devices. In this course, we will go into detail on how to modify the UserDetailPage view, which is part of a UWP application. Since UWP follows the MVVM (Model-View-ViewModel) architecture, we will adjust the layout and functionality of the UserDetailPage while adhering to these principles. We will also provide opportunities to practice through some example codes.

Understanding the Structure of UWP

UWP applications consist of several components. At its core, there are View, Model, and ViewModel. The View provides the user interface (UI). The Model manages data and business logic, while the ViewModel handles the interaction between the View and the Model.

What is UserDetailPage?

UserDetailPage is a screen that displays the user’s details. It is typically used to show information such as the user’s name, email, profile picture, and contact information. This page is an important user experience (UX) element as it helps users manage their information.

Setting Up the Basic UserDetailPage

First, let’s create a project and set up the basic UserDetailPage.

Step 1: Create a New UWP Project

Open Visual Studio and select New Project. Choose the UWP app template and set the project name to UserDetailApp. After the project is created, the default page MainPage.xaml will open.

Step 2: Add UserDetailPage

XAML


    
        
            
            
            
            
        
    

Step 3: Implement UserDetailPage Code Behind

C#
using Windows.UI.Xaml.Controls;

namespace UserDetailApp
{
    public sealed partial class UserDetailPage : Page
    {
        public UserDetailPage()
        {
            this.InitializeComponent();
            LoadUserData();
        }

        private void LoadUserData()
        {
            ProfilePicture.Source = new BitmapImage(new Uri("ms-appx:///Assets/profile.png"));
            UserName.Text = "John Doe";
            UserEmail.Text = "john@example.com";
        }

        private void EditButton_Click(object sender, RoutedEventArgs e)
        {
            // Edit user details logic
        }
    }
}

Improving UserDetailPage

The basic UserDetailPage displays user information in a very simple way. To enhance the user experience, let’s add some new features and designs.

Step 1: Add Profile Image Change Feature

We will add a feature that allows users to change their profile image. To do this, we will use the FileOpenPicker class to allow users to select an image from their local files.

C#
private async void EditButton_Click(object sender, RoutedEventArgs e)
{
    var picker = new Windows.Storage.Pickers.FileOpenPicker();
    picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary;
    picker.FileTypeFilter.Add(".jpg");
    picker.FileTypeFilter.Add(".png");

    var file = await picker.PickSingleFileAsync();
    if (file != null)
    {
        var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);
        var bitmap = new BitmapImage();
        bitmap.SetSource(stream);
        ProfilePicture.Source = bitmap;
    }
}

Step 2: Add User Name Edit Feature

Let’s add a text box to allow users to edit their names. We will modify the XAML layout to include the text box.

XAML


Now let’s add functionality to allow users to edit their names.

C#
private void SaveButton_Click(object sender, RoutedEventArgs e)
{
    UserName.Text = UserNameTextBox.Text;
}

Improving UI/UX

Step 1: Adding Styling

Now let’s add various styles and layouts to make the user interface (UI) look more appealing.

XAML

    



    

Step 2: Adding Animations

Adding animations to the page can make the user experience more engaging. Let’s add animations in XAML.

XAML

    
        
        
            
                
            
        
    

Conclusion

In this course, we have learned in detail how to modify the UserDetailPage view in UWP. Through the process of adding functionality to effectively manage and update user profiles, we believe you have laid the groundwork for practical application development. UWP development is a very flexible and powerful platform, making it a great way to realize your creative ideas.

We hope that the UserDetailPage you create will provide a better experience for users, and that you will continue to add more advanced features.

Thank you!