Reset Default Extension Default

I use the expander inside the Resizer (ContentControl with capture size) and it expands / collapses correctly when the control initially appears. As soon as I resize it, Expander will not crash correctly, as described below. I launched Snoop in my application, and I do not see any heights set on Expander or its components.

How can I convince Expander to crash again? Or changing the Resizer so as not to expand the Expander would also work.

Expander documentation says:

β€œFor the Expander to work correctly, do not specify the height in the Expander element if the ExpandDirection property is set to Down or Up. Similarly, do not specify the width of the Expander control if the ExpandDirection property is set to Left or right. When you set the size control of the Expander control in the direction of displaying the extended content, the area defined by the size parameter is displayed with a frame around it. This area is displayed even when the window is minimized. set the size of the extended window, "Dimension the size of the contents of the Expander or ScrollViewer control that spans the content."

+1
wpf expander
01 Oct '08 at 20:08
source share
4 answers

I have not had the opportunity to prototype this particular problem since then, but I recently discovered that setting Height or Width to Double.NaN resets it to default by default.

Ironically, this was from reading the Resizer control code that I used first.

+1
Feb 08 '09 at 17:24
source share

I solved the problem by moving the Resizer inside the Expander, but I ran into the Expander problem elsewhere, so I still need an answer if anyone has it.

thank

+1
01 Oct '08 at 20:34
source share

Answering this a little late (2+ years), but hey, better late than never, right?

In any case, I ran into this exact problem and was able to solve it using code to save and reset the width of the columns.

I have a 3 column grid with some content in the first column, GridSplitter in the second column and Expander in the third column. It appears that after moving the GridSplitter, the width of the column containing the Expander changes from Auto to a fixed size. This causes the expander to no longer collapse as expected.

So, I added a private variable and two event handlers:

private GridLength _columnWidth; private void Expander_Expanded (object sender, RoutedEventArgs e) { // restore column fixed size saved in Collapse event Column2.Width = _columnWidth; } private void Expander_Collapsed (object sender, RoutedEventArgs e) { // save current column width so we can restore when expander is expanded _columnWidth = Column2.Width; // reset column width to auto so the expander will collapse properly Column2.Width = GridLength.Auto; } 

When Expander expands, I keep the column2 fixed in width (which was changed from auto-in the background somewhere), and then reset the width to auto.

Then, when the expander expands, I return the column back to a fixed width so that it expands to the same width before it is collapsed.

Here is the XAML for reference:

 <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="2*" /> <ColumnDefinition Width="Auto" /> <ColumnDefinition x:Name="Column2" Width="Auto" /> </Grid.ColumnDefinitions> <ScrollViewer Grid.Column="0" VerticalScrollBarVisibility="Auto"> <!-- some content goes here --> </ScrollViewer> <GridSplitter HorizontalAlignment="Right" VerticalAlignment="Stretch" Grid.Column="1" ResizeBehavior="PreviousAndNext" Width="5" Background="Black" /> <Expander Grid.Column="2" ExpandDirection="Left" IsExpanded="True" Style="{StaticResource LeftExpander}" Expanded="Expander_Expanded" Collapsed="Expander_Collapsed"> <Grid> <TextBox TextWrapping="Wrap" Height="Auto" Margin="0 5 5 5" /> </Grid> </Expander> </Grid> 
+1
Dec 14 '10 at 16:41
source share

I had a similar problem using Expander inside a Grid with a GridSplitter. The expand / collapse behavior works fine until I move the splitter ... After that, Expander does not hide, it only hides its contents.

I'm still looking for a workaround ... did you finally find it?

0
Nov 13 '08 at 22:01
source share



All Articles