

In the mean time this reference app may also help you getting started with WinUI in UWP.
Uwp tabview upgrade#
This will give us an idea on how hard or easy it is to upgrade existing UWP apps to the new platform. It is our intention to upgrade this app with every new version of one of the underlying dependencies (specifically WinUI). It fetches and displays live financial data (stock prices and news) from IEX Cloud. To prepare ourselves for this WinUI 3.x we created a small but –hopefully- representative UWP app using WinUI 2.4.
Uwp tabview windows#
Version 3.x aims to become -in a not too distant future- the native runtime UI library for all apps that run on Windows – think Win32, UWP, Xamarin, Uno, and React Native. WinUI 2.x (currently version 2.4) is the production-ready predecessor of the ambitious WinUI 3 platform. If (_currentItemDetails.In this article we’ll walk through a UWP app that heavily relies on WinUI 2. If (detail = null) throw new ArgumentNullException(nameof(detail)) Public void RemoveItemDetail(ItemDetailViewModel detail) The RemoveItemDetail method removes the item from the observable collection and fires notification to change the current item: ViewModel = (Application.Current as App).Container.GetService() The view-model is created using the container: To connect the view to the view-model, in the code-behind file a ViewModel property is defined which is of type ListViewModel that was previously defined. The ItemTemplate of the ListBox defines a TextBlock that binds to the Title property of the item: _itemInfos = new ObservableCollection(itemsService.GetItemInfos()) įor the user interface, a ListBox control is defined that binds to the Info property of the view-model. _itemDetailViewModelFactory = itemDetailViewModelFactory _openItemsDetailService = openItemsDetailService Public ListViewModel(IItemsService itemsService, IOpenItemsDetailService openItemsDetailService, IItemDetailViewModelFactory itemDetailViewModelFactory) Private readonly ObservableCollection _itemInfos Private readonly IItemDetailViewModelFactory _itemDetailViewModelFactory Private readonly IOpenItemsDetailService _openItemsDetailService The returned items are stored within an ObservableCollection which allows adding items at a later time and automatically refresh the list with the user interface. With the constructor, the previously defined interface IItemsService will be injected to retrieve the items. The class ListViewModel will be bound to the first user control. The interface IItemsService is used for dependency injection to the view-model, and just contains the method GetItemInfos to return the large list of items: Public IEnumerable GetItemInfos() => _itemInfos ItemDetailId = Guid.NewGuid().ToString(), Public class ItemsService : IItemsServiceĭetails = Enumerable.Range(1, random.Next(1, 5)).Select(x1 => new ItemDetail This class creates 1000 items that contain a random number (1 to 5) of details: The items are created from the ItemsService class. The first user control contains the list of items, the second user control all the tabs of the currently opened details. The main window of the application contains two user controls: You can find the model of the application in the library DynamicTabLib, along with the view-models and services.

ItemDetail just contains information for the header and the content: The sub-items are defined by the ItemDetail class that is specified by a property of type IEnumerable: The item is defined by the class ItemInfo.

Within the application a large list of items should be shown on the left side. You can build and run the sample application with Visual Studio 2017 RC.
Uwp tabview code#
Visual Studio 2017 – some of the code makes use of C# 7.0.Technologies, tools, and frameworks used in this article: In this blog article you can read about using the Pivot control (instead of TabControl) with the MVVM pattern to open tabs dynamically as items from a ListBox are selected. This article uses the same view-model library, but now the client application is using the Universal Windows Platform (UWP).
Uwp tabview how to#
In a previous blog article I explained how to dynamically open tabs with WPF.
