Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 158 Stack Exchange communities.

What is meta?
Here's how it works:
  1. Any Stack Exchange user can ask a question
  2. The community provides support, votes on ideas, and reports bugs
  3. Your voice helps shape the way Stack Exchange operates

The question Adaptive layouts in WPF was closed, because it is "vague, overly broad, and cannot be reasonably answered".

As you can see, I have a serious problem with WPF and I need to solve it. How to formulate the question and what information to add to make it good enough for Stack Overflow?

Do I need to show exact layouts and conditions for them? The problem is, there may be multiple approaches, and restricting to some exact layout examples could limit answers and I'd like to avoid that. For example, if I receive a comment, "You can't do that with StackPanel, but can do it with Grid", I'd effectively be forced to create yet another question so that the person could answer. It seems counterproductive to me.

share|improve this question
I think in some sense you've answered your own question. Do I need to show exact layouts and conditions for them? The problem is, there may be multiple approaches, and restricting to some exact layout examples could limit answers and I'd like to avoid that. - it may well be different approaches are better, but SO is more for I've tried this approach and it fails (here's the code - can someone help me to understand why) - not "what are my approaches" - maybe programmers (or potentially more specific forum) would be more appropriate. – Jon Clements Dec 26 '12 at 16:00
up vote 1 down vote accepted

Because of the way WPF works, I think this question is fine for SO and have voted to reopen it. There is a reasonable and easy answer to the question based on the technology it uses.

The best way is to use DataTriggers on the parent element's ActualHeight or ActualWidth properties that sets child properties such as Grid.Row / Grid.Column, StackPanel.Orientation, or DockPanel.Dock to position items based on the size of the parent element.

Another method I've used in the past is to hook into the Loaded and SizeChanged event of the parent, and alter the visibility (or other properties) of the child objects based on if they're completely or partially visible.

But I'm getting off track here.

I've made a fairly significant edit to your question in an attempt to get it reopened.

Originally, it appeared at first glance to be an extremely broad question, and that image wasn't helped by having multiple example scenarios, none of which were actual code you appear to be using.

I've edited it to remove much of the extra text, and reduced it down to just one of your example scenarios that seems to adequately describe your situation.

It should be answerable in its current form, and I've voted to reopen it. If its not reopened in a few days and the votes start to expire, you can flag it for a moderator and explain it's been significantly edited, and ask for it to be reopened.

And if it does get reopened, I'll see about writing a full answer about how easy it is to do fluid layouts in WPF.

share|improve this answer
This is the solution I've thought about, but I don't particularly like it, because the code will quickly become unreadable. Grid layouts aren't very readable to start with, but with multiple layouts stuffed into them, with setters adjusting not only properties of controls, but properties of grid's columns and rows, I'm afraid the code will become incomprehensible. Ribbon controls, for example use "placeholders" approach . I hoped there's a more generic way. – Squidward Dec 26 '12 at 18:35
@Athari You can replace entire Templates in a DataTrigger too, which is a much simpler way of rearranging complex views. Usually I use DataTemplates, then set a ContentControl.ContentTemplate property based on a DataTrigger, although depending of the nature of the data I'm working with, I could also do something like an ItemsPanelTemplate and an ItemsControl.ItemsPanel – Rachel Dec 26 '12 at 19:03
I've never thought of completely replacing templates using triggers. Sounds promising! Won't be as fast as just rearranging, but with ribbons and other complex controls resizing is relatively slow anyway. – Squidward Dec 26 '12 at 19:11
I reopened the question with your edits, Rachel. It sounds like you might also have an answer in mind to post there, so feel free. I also noodled on migrating to Programmers, but it looks like it may be a bit too code-focused for that (although the mods weren't necessarily opposed when I asked for a sanity check). Still, the question's good on SO as is, and is now reopened. (cc @Athari) – Adam Lear Dec 26 '12 at 22:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .