UWP development, Xamarin, XAML, C#

UWP (Universal Windows Platform) is an app development platform provided by Microsoft, used to create applications that can run on a variety of Windows 10 devices. UWP leverages the integrated user experience of Windows to provide developers with a powerful environment to develop through strong APIs, various tools, and languages (especially C#).

Basic Concepts of UWP

UWP allows you to create apps that can operate on multiple devices with a single code base. UWP apps are built to run on all devices that run Windows 10. This freedom provides a consistent user experience across various devices, saving time for both developers and users.

Main Features of UWP

  • Device Multiplexing: UWP apps run on PCs, tablets, smartphones, and Xbox.
  • Security: UWP runs in a sandbox environment, requiring apps to explicitly request permissions to access system resources.
  • State Persistence: Apps can securely store user data on the local device through state management.

Developing UWP Apps with Xamarin

Xamarin is a platform that allows you to build iOS, Android, and UWP apps using C#. Using Xamarin maximizes code reuse and provides powerful UI capabilities.

Basic Components of Xamarin

Xamarin follows the MVVM (Model-View-ViewModel) architecture through the components of View, ViewModel, and Model. This allows for a clear separation of business logic and the UI.

Basic Xamarin Project Setup


        public partial class MainPage : ContentPage
        {
            public MainPage()
            {
                InitializeComponent();
                // Button click event handler
                var button = new Button { Text = "Click Here" };
                button.Clicked += OnButtonClicked;
                Content = new StackLayout { Children = { button } };
            }

            private void OnButtonClicked(object sender, EventArgs e)
            {
                DisplayAlert("Notification", "The button has been clicked!", "OK");
            }
        }
    

Importance of XAML

XAML (Extensible Application Markup Language) is a markup language used to define the UI of UWP and Xamarin applications. XAML helps declaratively define UI components and their properties.

Structure of XAML


        
            
                
            
        
    

Event Handling


        private void OnClick(object sender, RoutedEventArgs e)
        {
            MyButton.Content = "Clicked!";
        }
    

Structuring UWP App Logic with C#

C# is the most widely used programming language in UWP, offering strong object-oriented features and various libraries. The example below demonstrates how to create a simple To-Do list app in C# using data binding and the MVVM pattern.

Defining the Model


        public class TodoItem
        {
            public string Title { get; set; }
            public bool IsCompleted { get; set; }
        }
    

Defining the ViewModel


        public class TodoViewModel : INotifyPropertyChanged
        {
            private ObservableCollection _todos;
            public ObservableCollection Todos
            {
                get { return _todos; }
                set { _todos = value; OnPropertyChanged(nameof(Todos)); }
            }

            public TodoViewModel()
            {
                Todos = new ObservableCollection();
                Todos.Add(new TodoItem { Title = "First Task", IsCompleted = false });
            }

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

View and Data Binding


        
            
        

        
            
                
                    
                        
                        
                    
                
            
        
    

Conclusion

UWP is an integrated platform for modern app development, allowing the creation of applications that can run on various devices. It is possible to create efficient and powerful apps using Xamarin, XAML, and C#, with all these elements working together to provide an excellent user experience. There are no limits to combining these technologies, allowing for various creative ways to deliver value to users.