locked
Why doesn't whatever is in one expander push everything below it down???? RRS feed

  • Question

  • I'm already weeks late on providing a prototype, and I'm still struggling with the basics of WPF and SketchFlow.  My patience is at an end.  Unfortunately, I get no help, as we have no budget for training, so I get further and further behind.

    I would like to know why in &&*&$*$%*&%% putting one expander above another, and then expanding the one on top, does not push the expanders below it down??????????????????????????????????????????????  Instead the stupid thing overlaps whatever is there.  If this were a <div> on a HTML page, I am certain it would push the rest of the content on the page down, why doesn't it work like that in WPF??????????????


    Rod
    Monday, March 22, 2010 9:03 PM

Answers

  • Rod, please keep in mind that most people here are volunteers that answer questions just to help out other people, especially people just learning the WPF/Silverlight platform.

    Now, on to your question.  It sounds like you need to put your expanders into a layout container that knows how to move things around, which in this case is probably a stackpanel.  If you put several expanders into a stack panel, you basically get an accordian control that can have multiple panes open at a time. Of course you can use an accordian control and set it to allow multiple open panes as well.

    Here is an example of both expanders in a stackpanel and an accordian control set to allow mutiple panes to be open:

    <Window
    	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    	xmlns:System_Windows_Controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Layout.Toolkit"
    	x:Class="WpfApplication15.MainWindow"
    	x:Name="Window"
    	Title="MainWindow"
    	Width="640" Height="480">
    
    	<Grid x:Name="LayoutRoot">
    		<StackPanel Margin="35,141,251.87,76">
    			<Expander VerticalAlignment="Top" Header="Expander">
    				<StackPanel>
    					<Button HorizontalAlignment="Left" Width="75" Content="Button"/>
    					<Button HorizontalAlignment="Left" Width="75" Content="Button"/>
    				</StackPanel>
    			</Expander>
    			<Expander VerticalAlignment="Top" Header="Expander">
    				<StackPanel>
    					<TextBlock HorizontalAlignment="Left" TextWrapping="Wrap"><Run Text="TextBlock"/></TextBlock>
    					<TextBlock HorizontalAlignment="Left" Text="TextBlock" TextWrapping="Wrap"/>
    				</StackPanel>
    			</Expander>
    			<Expander VerticalAlignment="Bottom" Header="Expander">
    				<Grid>
    					<ListBox HorizontalAlignment="Left" Width="100">
    						<ListBoxItem Content="ListBoxItem"/>
    						<ListBoxItem Content="ListBoxItem"/>
    					</ListBox>
    				</Grid>
    			</Expander>
    		</StackPanel>
    		<System_Windows_Controls:Accordion HorizontalAlignment="Right" Margin="0,44,81,76" Width="183.87" VerticalAlignment="Stretch" SelectionMode="OneOrMore" SelectionSequence="CollapseBeforeExpand">
    			<System_Windows_Controls:AccordionItem>
    				<ListBox Width="100" Height="100">
    					<ListBoxItem Content="ListBoxItem"/>
    					<ListBoxItem Content="ListBoxItem"/>
    				</ListBox>
    			</System_Windows_Controls:AccordionItem>
    			<System_Windows_Controls:AccordionItem>
    				<StackPanel Width="0" Orientation="Vertical">
    					<TextBlock HorizontalAlignment="Left" TextWrapping="Wrap"><Run Text="TextBlock"/></TextBlock>
    					<TextBlock HorizontalAlignment="Left" TextWrapping="Wrap"><Run Text="TextBlock"/></TextBlock>
    				</StackPanel>
    			</System_Windows_Controls:AccordionItem>
    			<System_Windows_Controls:AccordionItem>
    				<StackPanel Width="100" Height="100">
    					<Button Content="Button"/>
    					<Button Content="Button"/>
    				</StackPanel>
    			</System_Windows_Controls:AccordionItem>
    		</System_Windows_Controls:Accordion>
    	</Grid>
    </Window>

    • Marked as answer by Rod at Work Tuesday, March 23, 2010 2:55 PM
    Tuesday, March 23, 2010 12:38 PM
    Moderator

All replies

  • Rod, please keep in mind that most people here are volunteers that answer questions just to help out other people, especially people just learning the WPF/Silverlight platform.

    Now, on to your question.  It sounds like you need to put your expanders into a layout container that knows how to move things around, which in this case is probably a stackpanel.  If you put several expanders into a stack panel, you basically get an accordian control that can have multiple panes open at a time. Of course you can use an accordian control and set it to allow multiple open panes as well.

    Here is an example of both expanders in a stackpanel and an accordian control set to allow mutiple panes to be open:

    <Window
    	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    	xmlns:System_Windows_Controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Layout.Toolkit"
    	x:Class="WpfApplication15.MainWindow"
    	x:Name="Window"
    	Title="MainWindow"
    	Width="640" Height="480">
    
    	<Grid x:Name="LayoutRoot">
    		<StackPanel Margin="35,141,251.87,76">
    			<Expander VerticalAlignment="Top" Header="Expander">
    				<StackPanel>
    					<Button HorizontalAlignment="Left" Width="75" Content="Button"/>
    					<Button HorizontalAlignment="Left" Width="75" Content="Button"/>
    				</StackPanel>
    			</Expander>
    			<Expander VerticalAlignment="Top" Header="Expander">
    				<StackPanel>
    					<TextBlock HorizontalAlignment="Left" TextWrapping="Wrap"><Run Text="TextBlock"/></TextBlock>
    					<TextBlock HorizontalAlignment="Left" Text="TextBlock" TextWrapping="Wrap"/>
    				</StackPanel>
    			</Expander>
    			<Expander VerticalAlignment="Bottom" Header="Expander">
    				<Grid>
    					<ListBox HorizontalAlignment="Left" Width="100">
    						<ListBoxItem Content="ListBoxItem"/>
    						<ListBoxItem Content="ListBoxItem"/>
    					</ListBox>
    				</Grid>
    			</Expander>
    		</StackPanel>
    		<System_Windows_Controls:Accordion HorizontalAlignment="Right" Margin="0,44,81,76" Width="183.87" VerticalAlignment="Stretch" SelectionMode="OneOrMore" SelectionSequence="CollapseBeforeExpand">
    			<System_Windows_Controls:AccordionItem>
    				<ListBox Width="100" Height="100">
    					<ListBoxItem Content="ListBoxItem"/>
    					<ListBoxItem Content="ListBoxItem"/>
    				</ListBox>
    			</System_Windows_Controls:AccordionItem>
    			<System_Windows_Controls:AccordionItem>
    				<StackPanel Width="0" Orientation="Vertical">
    					<TextBlock HorizontalAlignment="Left" TextWrapping="Wrap"><Run Text="TextBlock"/></TextBlock>
    					<TextBlock HorizontalAlignment="Left" TextWrapping="Wrap"><Run Text="TextBlock"/></TextBlock>
    				</StackPanel>
    			</System_Windows_Controls:AccordionItem>
    			<System_Windows_Controls:AccordionItem>
    				<StackPanel Width="100" Height="100">
    					<Button Content="Button"/>
    					<Button Content="Button"/>
    				</StackPanel>
    			</System_Windows_Controls:AccordionItem>
    		</System_Windows_Controls:Accordion>
    	</Grid>
    </Window>

    • Marked as answer by Rod at Work Tuesday, March 23, 2010 2:55 PM
    Tuesday, March 23, 2010 12:38 PM
    Moderator
  • Chuck, you are quite right.  I'm not angry at anyone here.  I'm anxious because the learning curve for WPF is way higher, in my opinion, then the time I have to spend on it, and yet I'll never advance if I don't spend time at it, and yet I don't have the time to spend on it because my supervisors are getting impatient, etc.  I'm really caught in a catch-22 situation here.

    Thank you for the suggestion of using some sort of layout control; I'll do that.  But WOW, how am I supposed to know that?  I've got a book on WPF ("Pro WPF in C# 2008", by Matthew MacDonald, pub. Apress), and I looked up the Expander control, and frankly never thought of the possibility that something else would have to be involved to achieve what I'm looking for.  I'm so ignorant of all of this stuff that I don't even know the question to ask, let alone ask it.  I worry, what else am I totally unaware of that will bite me?  How many other things are there to know, which I've no idea that I don't know, that will bite me?  This reminds me of my attempt, ~15 years ago, of trying to learn how to program Windows using MFC and C++.  I got a book on MFC programming and followed along in a tutorial of writing a graphics program, but the thing that frustrated me was that no where did that book ever say, "You are doing this because......"  All you could do was be a good monkey and duplicate what they did, without ever knowing why.  Eventually I gave up trying to learn MFC, because I couldn't understand why I did whatever the author told me to do, and therefore I could never design any application that wasn't precisely like his.  This reminds me of that. I didn't know that Expanders have "something" which don't allow them to push other controls aside unless they're contained within some sort of layout control.  I didn't understand that, whatever else layout controls do, one thing they do is allow expanders to expand and push other controls aside.  What then is the purpose of an expander control outside of the context of some layout control?  If the ability to expand and push other controls aside was not incorporated into the expander control, then what was the reason for doing that?  Why is a layout control necessary to do that?  What does one hope to achieve by having a expander control occlude other controls beneath it, if it is not in a layout control?  Why would one want to occlude other controls with an expander control when its expanded?  Since its possible to do that, then one has to wonder what it is one would try to be achieving, because that functionality is allowed, so there's probably some reason why you would want to do that.

    Man, I wish I could get some classroom training on this.  That way I could ask my questions, most of which will be "Why was this done?", "Why was this action decided upon and not another?", "What was the WPF team trying to achieve when they decided XAML should behave this way in this situation rather than another?", etc.  You don't get answers to those questions in a book.


    Rod
    Tuesday, March 23, 2010 3:23 PM
  • Hi Rod,

    do you know Deep Thought? Deep Thought had the ultimate answer to all questions ever ask: The answer was "42". The reason because Deep Thought answered "42" was, that he was asked for a Why ... Why does nature exist? Why does the universe exist? Etc. ...

    I mean ... if Deep Thought would not have been asked for an answer to a Why-Question the answer would have been totally different. If one would have put another kind of question to him ... e.g. on How things work or What happens when .... Deep Thought's approach would have been totally different. And he would have had a much better and satisfactory expierence about the things he explored.

    Exploring the "how to" makes life easier.

    M.

    Thursday, March 25, 2010 12:59 PM