Repository navigation
What's new in TableView: hierarchical views, context menus and live data 📊 #12762
Pranav Gupta (pranav-gupta-msft)
announced in
Announcements
Replies: 1 comment
|
Hi Pranav Gupta (@pranav-gupta-msft), thank you for addressing these issues! TableView still has some limitations when working with MVVM and code-behind. Both Also, wouldn't it be better to create a dedicated repository for TableView samples instead of copy-pasting code snippets here? That would make the samples easier to maintain, discover, and contribute to. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Hello WinUI community!
TableView is experimental and still a work in progress. APIs and behavior may change between releases. If something doesn't work as expected, please file an issue.
When we introduced TableView, we said hierarchical views and app context menus were next. Both are available in Windows App SDK 2.6.6-experimental, along with live shaping, so rows re-sort and re-filter as your data changes.
This post picks up where the first one left off. Contoso Sales Ledger gets two new views: Accounts, a Region → Account → Deal tree, and Live board, an end-of-quarter board where amounts change while you watch. The original Ledger view gets context menus on rows, cells and column headers.
As before, the full-ledger screenshots include app-defined toolbar controls and KPI cards; these are not built-in TableView UI.
The runnable excerpts continue the
SalesLedgertutorial from the first post, with the same twelve deals. Each step is a point-in-time version. InMainWindow.xaml, replace the content inside your existingWindow. InMainWindow.xaml.cs, keep the imports and namespace and replace the class definitions. Project setup, updated for 2.6.6, is in Try it out.🌳 Hierarchical views
Sales data is rarely flat. A region has accounts and an account has deals, and whoever reviews the pipeline wants totals at each level before drilling in.
TableView builds the tree from a flat list. Each row carries its own key and its parent's key, and
TableViewSource.ParentByconnects them. A row whose parent key isnullbecomes a root. You don't need a children collection on your model, and the sort, filter and selection you already use keep working on the tree.Expanding works with the mouse and the keyboard. Right expands a row, Left collapses it (or moves to its parent), and
*expands the whole subtree.TableView.ExpandAllRows()andCollapseAllRows()do the same for every row, and eachTableViewRowexposesLevel,IsExpandedandIsExpandableif you style rows by depth.For this step, the tutorial flattens the twelve deals into Region → Owner → Deal rows. Parent rows hold rolled-up totals, and the Pipeline column gets a
MinWidthso nested rows have room for their indent.Extra C# import for this step:
System.Linq.MainWindow.xaml: content inside Window
MainWindow.xaml.cs: flat rows with Id and ParentId
Run it and the ledger opens with four collapsed regions sorted by rolled-up amount: South $124,500, West $115,000, North $69,500 and East $20,200.
Sortapplies at every level, so owners and deals inside a region are ordered by Amount too.Filters work on the tree, too. A matching row keeps its ancestors, and they expand to show it. Type
cloudand you get West › Maya Chen › Cloud analytics and Cloud migration, plus East › Alex Rivera › Cloud backup. Clear the box and the full tree comes back.🖱️ Context menus
People act on what they see in a ledger. They copy a deal into an email, mark it won or hide a column they don't need, and they expect a right-click or the Menu key to get them there.
TableView now has a menu at each level of the table:
ContextFlyoutonTableViewRow, set through an implicit styleTableViewColumn.CellContextFlyoutTableViewColumn.HeaderContextFlyoutTableView.ContextFlyoutThe most specific menu wins. A cell menu replaces the row menu for that column, and other cells fall back to the row menu.
Menu items get the right-clicked row's data item as their
DataContext, so a click handler reads theDealfrom its sender.MainWindow.xaml: content inside Window
Header menus are built in code, one per column, so each Hide item already knows its column. An
Openinghandler disables Hide when only one column is left, so the table never ends up empty.Extra C# imports for this step:
System.ComponentModel,System.LinqandWindows.ApplicationModel.DataTransfer.MainWindow.xaml.cs: menus and a notifying Deal
Right-click Office refresh and choose Mark as won, and its Stage changes to Won immediately because
DealraisesPropertyChanged. Copy deal puts a tab-separated line on the clipboard. Right-click an Amount cell and you get only Copy amount. Right-click the Owner header and choose Hide Owner; Show all columns brings it back.⚡ Live data updates
At the end of a quarter, reps log new numbers all day, and the board the sales team is watching has to keep up without a refresh button.
Set
TableViewSource.IsLiveShaping = true, and aPropertyChangedon any item re-applies the current sort and filter for that item. A deal whose amount passes its neighbour slides to its new position. A deal that crosses a filter threshold joins or leaves the view. If the row was selected, it stays selected as it moves.You can turn live shaping off at any time. With
IsLiveShaping = false, cell values still update, but rows stay in place until you sort or filter again. That's useful while someone is reading or editing a row that would otherwise move under them.This step drops the hierarchy and menus to keep the code short. A
DispatcherTimerstands in for your real data feed: every second it nudges up to three deals by as much as $2,500. The timer starts when the table loads and stops when it unloads.Extra C# import for this step:
System.ComponentModel.MainWindow.xaml: content inside Window
MainWindow.xaml.cs: timer, live shaping and a notifying Deal
Run it and the twelve deals tick every second. Cloud migration and Cloud analytics trade places regularly, and the Change column shows ▲ or ▼ with the size of each move. Select a row and it stays selected wherever it goes. Turn Live shaping off and the numbers keep moving while the rows hold still. Turn on the Amount ≥ $30,000 filter and five deals remain; others join or drop out as they cross the line.
In a real app the timer would be a network feed, a SignalR hub or a database change notification. TableView only needs
PropertyChangedfrom your items. If updates arrive on a background thread, raise them on the UI thread withDispatcherQueue.TryEnqueue.Try it out
Install Microsoft.WindowsAppSDK 2.6.6-experimental and explore the experimental Tabular API reference. If you followed the first post, update the package version and add the new imports listed for each step.
Project setup
Create a C# WinUI 3 app named
SalesLedgerwith Microsoft.WindowsAppSDK 2.6.6-experimental. Keep the template'sApp.xaml.cs.PropertyGroup, setWindowsAppSDKSelfContained=true,WindowsPackageType=NoneandEnableMsixTooling=false.Properties\launchSettings.json, use an unpackaged profile withcommandNameset toProject, and select it in Visual Studio.XamlControlsResourcesandTabularControlsResourcesin application resources; addxmlns:tv="using:Microsoft.UI.Xaml.Controls.Tabular"to the existingWindow.System,System.Collections.Generic,System.ComponentModel,System.Globalization,System.Linq,Microsoft.UI.Xaml,Microsoft.UI.Xaml.Controls,Microsoft.UI.Xaml.Controls.Tabular,Microsoft.UI.Xaml.DataandWindows.ApplicationModel.DataTransfer.💬 Tell us what you think
TableView is still experimental. Hierarchy, context menus and live shaping are new in this release, and we expect you'll find rough edges. Tell us what your trees look like, which menus you need, and how fast your data changes.
Thank you to everyone who tried the first release and filed reports. Here are some of the issues the community raised:
Check existing TableView issues first. If you hit the same problem, add your repro there; for a new one, file an issue with the Windows App SDK version, steps to reproduce, what you expected and what happened. Broader feedback is welcome in WinUI discussions.
Pranav Gupta
Team WinUI 💙
All reactions