开发者

Controlling position of input controls based on visibility

I have a weird requirement. 开发者_JS百科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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜