I have a WPF window with SizeToContent="Height" . This window contains <Expander /> , which displays a list of recent activities. I would like the extension of the expander to increase the window size proportionally. When hiding, the window again proportionally changes. If the window is resized, the expander and it must contain a list in order to use the new space. (not against the colors there to help me figure this out):
Normal view
alt text http://www.deploylx.com/so/wpfexpander/Open.png
Collapsed
alt text http://www.deploylx.com/so/wpfexpander/Closed.png
Changed to a new space
alt text http://www.deploylx.com/so/wpfexpander/Expanded.png
So far, this works great. The problem occurs when <Expander /> crashes after resizing the window. Instead of the window crashing down again, the list view is simply hidden:
Resets after resizing
alt text http://www.deploylx.com/so/wpfexpander/Collapsed.png
My intuition tells me that the Height window of the window is set when the window is resized and thus overrides the SizeToContent property. So, how can I get a window to preserve its size for the behavior of the content after changing it?
Current XAML:
<Window x:Class="DeployLX.Licensing.Nlm.Admin.v3.DashboardWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Dashboard" Width="504" SizeToContent="Height" Height="275"> <DockPanel> <Menu DockPanel.Dock="Top"> <MenuItem Header="_File"> <MenuItem Header="E_xit" Command="{Binding Path=CloseCmd}" /> </MenuItem> </Menu> <Grid DockPanel.Dock="Top" Margin="8" ShowGridLines="True"> <Grid.RowDefinitions> <RowDefinition /> <RowDefinition /> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition /> <ColumnDefinition /> </Grid.ColumnDefinitions> <Grid Grid.RowSpan="2" Grid.Row="0" Grid.Column="0" Margin="0,0,8,0"> <Rectangle Fill="Red" /> <TextBlock>ActiveCount</TextBlock> </Grid> <Grid Grid.Row="0" Grid.Column="1" Margin="0,0,0,4"> <Rectangle Fill="Green" /> <TextBlock>Authorization</TextBlock> </Grid> <Grid Grid.Row="1" Grid.Column="1" Margin="0,4,0,0"> <Rectangle Fill="Blue" /> <TextBlock>Authorization</TextBlock> </Grid> </Grid> <Expander Header="Recent Activity" Margin="8" IsExpanded="True"> <ListView IsSynchronizedWithCurrentItem="True" MinHeight="100"> <ListView.View> <GridView> <GridViewColumn Header="Status"/> </GridView> </ListView.View> </ListView> </Expander> </DockPanel> </Window>
UPDATE:. I tried to listen to the expander's Collapsed event and reset the Windows SizeToContent property. It almost works. This will force it to minimize the window again, but as it expands, it returns to its original height of 100 pixels. Although it is possible to store and capture this information, it smells like hacks and is prone to errors.
Paul Alexander May 08 '09 at 9:00 p.m. 2009-05-08 21:00
source share