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. WPF
  4. Common StackPanel being used in two places, with Horizontal and Vertical Orientations

Common StackPanel being used in two places, with Horizontal and Vertical Orientations

Scheduled Pinned Locked Moved WPF
csharpwpfwinformsquestion
4 Posts 2 Posters 5 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.
  • A Offline
    A Offline
    Amarnath S
    wrote on last edited by
    #1

    I have a set of five buttons, in a StackPanel, which is a user control. I would like to use this same StackPanel in two different places on the screen, with different orientations - Horizontal in one place, and Vertical in the other place. Is it possible to do it in WPF? (I can have two different user controls, but most of the code will be same between the two, the only difference being in their orientations. I would like to reuse the StackPanel in both these places, with different orientations). Thanks in advance.

    L 1 Reply Last reply
    0
    • A Amarnath S

      I have a set of five buttons, in a StackPanel, which is a user control. I would like to use this same StackPanel in two different places on the screen, with different orientations - Horizontal in one place, and Vertical in the other place. Is it possible to do it in WPF? (I can have two different user controls, but most of the code will be same between the two, the only difference being in their orientations. I would like to reuse the StackPanel in both these places, with different orientations). Thanks in advance.

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

      Use the .Tag property of the user control (UC) to pass the orientation ("H" or "V") to the UC's Loaded event. Then set the orientation of the stack panel based on the value of .Tag in the UC's Loaded event.

      string tag = this.Tag as string;

      xxx.Orientation = (tag == "H") ? Orientation.Horizontal : Orientation.Vertical;

      It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food

      A 1 Reply Last reply
      0
      • L Lost User

        Use the .Tag property of the user control (UC) to pass the orientation ("H" or "V") to the UC's Loaded event. Then set the orientation of the stack panel based on the value of .Tag in the UC's Loaded event.

        string tag = this.Tag as string;

        xxx.Orientation = (tag == "H") ? Orientation.Horizontal : Orientation.Vertical;

        It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food

        A Offline
        A Offline
        Amarnath S
        wrote on last edited by
        #3

        Thank you very much. Will try this out in my code.

        L 1 Reply Last reply
        0
        • A Amarnath S

          Thank you very much. Will try this out in my code.

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

          You're welcome!

          It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food

          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