Generate a WPF-Menu based on a XML-document
-
Hello! I want to represent a WPF-Menu based on a XML-file. The file looks like this:
The goal is to be able to expand the menu at any time. I hope someone can help me. Best regards!
-
Hello! I want to represent a WPF-Menu based on a XML-file. The file looks like this:
The goal is to be able to expand the menu at any time. I hope someone can help me. Best regards!
-
Preferably all of it. I know, how to read a XML-file, but I cant display the data as a menu. So I don't know the connection of these things ...
-
Hello! I want to represent a WPF-Menu based on a XML-file. The file looks like this:
The goal is to be able to expand the menu at any time. I hope someone can help me. Best regards!
Deserialize the XML document to a collection of say
Menu
objects. Then do the necessary binding to reflect what you want in the view."As beings of finite lifespan, our contributions to the sum of human knowledge is one of the greatest endeavors we can undertake and one of the defining characteristics of humanity itself"
-
Preferably all of it. I know, how to read a XML-file, but I cant display the data as a menu. So I don't know the connection of these things ...
Member 13100573 wrote:
Preferably all of it.
In that case you'd be asking for a developer for hire.
Member 13100573 wrote:
I know, how to read a XML-file, but I cant display the data as a menu.
Creating a menu dynamically isn't that hard in WinForms, so I would expect it not to be too hard in WPF either. You could search for an example and give it a try - if you get stuck and have a specific question we can help.
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)
-
Hello! I want to represent a WPF-Menu based on a XML-file. The file looks like this:
The goal is to be able to expand the menu at any time. I hope someone can help me. Best regards!
And what, exactly, do you want to happen when the user clicks on a menu item? If you want to know how to construct the menu itself, search for articles on MVVM menus with WPF.
This space for rent
-
Hello! I want to represent a WPF-Menu based on a XML-file. The file looks like this:
The goal is to be able to expand the menu at any time. I hope someone can help me. Best regards!
You should start to read about XmlDataProvider and how to use bindings to XML-documents with XPath. A good starting point can be How to: Bind to XML Data Using an XMLDataProvider and XPath Queries | Microsoft Docs[^] In the example a ListBox is populated but you should be able to replace it with a Menu bound to an XmlDataProvider as ItemsSource with a customized ItemContainerStyle that sets the Header of the MenuItem to the title attribute. Good luck.