简体   繁体   中英

Controlling position of input controls based on visibility

I have a weird requirement. I want to have input controls on a xaml page based on some condition. There are two ways to do it. Either create them at runtime and position them accordingly or have them on the page by default and set its visibility. In short, I want to dynamically control the position of input controls like textbox or calender control based on its visibility and align itself at runtime (placing them horizontally). Here is a rough sketch of want I am trying to achieve..

[TEXTBOX 1] [TEXTBOX 2] [BUTTON] --> [TEXTBOX 1] [BUTTON]

How do i do it?

Your diagram does not indicate if you want fixed positions etc, but changing the visibility on existing controls is always the easiest option.

Stackpanels (set to Horizontal orientation) are most convenient container if you want your invisible controls to collapse up the space in between.

The usual way of controlling visibility is to bind them to bool properties on your ViewModel, using a VisibilityConvertor to turn bool values into Visibility.Visible/Collapsed, but that is in the MVVM pattern. In a code-behind-only scenario you just set the Visibility of the controls.

If you can provide more detail, I can provide specific examples.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM