Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Generate a WPF-Menu based on a XML-document

Generate a WPF-Menu based on a XML-document

Scheduled Pinned Locked Moved C#
csharpwpfxmlhelp
7 Posts 5 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 13068527
    wrote on last edited by
    #1

    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!

    L M P H 4 Replies Last reply
    0
    • U User 13068527

      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!

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Help with what exactly? Reading XML, generating a menu, or all of it?

      Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)

      U 1 Reply Last reply
      0
      • L Lost User

        Help with what exactly? Reading XML, generating a menu, or all of it?

        Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)

        U Offline
        U Offline
        User 13068527
        wrote on last edited by
        #3

        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 ...

        L 1 Reply Last reply
        0
        • U User 13068527

          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!

          M Offline
          M Offline
          Meshack Musundi
          wrote on last edited by
          #4

          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"

          1 Reply Last reply
          0
          • U User 13068527

            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 ...

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            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)

            1 Reply Last reply
            0
            • U User 13068527

              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!

              P Offline
              P Offline
              Pete OHanlon
              wrote on last edited by
              #6

              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

              1 Reply Last reply
              0
              • U User 13068527

                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!

                H Offline
                H Offline
                Henrik Jonsson
                wrote on last edited by
                #7

                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.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups