Common StackPanel being used in two places, with Horizontal and Vertical Orientations
-
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.
-
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.
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
-
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
Thank you very much. Will try this out in my code.
-
Thank you very much. Will try this out in my code.