0

I am developing a WINUI 3 application. In one portion of the application I need to display a hierarchical structure very similar to an XML with 4–5 levels of nesting. The structure must be flattened into a plain text that uses different colors to represent the different level of nesting.

Each level needs to be displayed with its own style. I was thinking of using a TextBlock hosted in Scrollview container. However, I need to support the two following operations:

A) Master-Detail view : when the user clicks on one node, I need to display related information into another part of the application. B) Navigation : when pressing the left/right cursor, I need to travel to the previous/next node at the same level of nesting, which might be outside the current view of the application.

In order to do that:

  • for A) I need to identify the portion of text that is being clicked on. I was thinking of using HyperLinks, but the OnClick event receives an Id and Name that are read-only.
  • for B) I need to scroll the view automatically to the next node that might be outside the current view and I really haven't found any property that allows me to identify "where the next node" is and any method that allows me to force scrolling the view to that point.

In addition to that of course I need to generate dynamically the TextBlock and I have found any better way that to use a XamlReader.Load. However, when doing that, I cannot set the Name and Uid properties that could allow me to identify the hyperlink in the OnClick event.

Is what I am trying to achieve even feasible in WinUI3? What is the approach you would suggest?

Ken White
  • 123,280
  • 14
  • 225
  • 444
lucaregini
  • 21
  • 3
  • I would start with ``TreeView``. You can create a ``DataTemplateSelector`` to switch styles for your items. See [here](https://learn.microsoft.com/en-us/windows/apps/design/controls/tree-view#:~:text=Item%20template%20selectors). – Andrew KeepCoding Feb 22 '23 at 02:24
  • This [answer](https://stackoverflow.com/a/75529010/2411960) and this [answer](https://stackoverflow.com/a/75320554/2411960) are about ``TreeView`` with ``DataTemplateSelector``. – Andrew KeepCoding Feb 22 '23 at 06:39
  • What I am really try to do is almost a scrollable rich text control with clickable elements inside. From the documentation I understood that elements in a treeview are stacked while I need everything inline like a text blob. An additional requirement is that the control should be supported by UNO. – lucaregini Feb 23 '23 at 07:33
  • The [TokenizingTextBox](https://learn.microsoft.com/en-us/windows/communitytoolkit/controls/tokenizingtextbox) from the WindowsCommunitToolkit might give you a hint then. You can see how it's implemented [here](https://github.com/CommunityToolkit/WindowsCommunityToolkit/tree/20f951e928cc4fbb0c6eafa7949b13c7c1e66ff4/Microsoft.Toolkit.Uwp.UI.Controls.Input/TokenizingTextBox). – Andrew KeepCoding Feb 24 '23 at 02:16

0 Answers0