Alex Rivera | Logout

How do you keep the WPF window sized to content with an Expander after resize

Asked 2009-05-08T21:00:01.950
56

I've got a WPF window with SizeToContent="Height". This window contains an <Expander /> that displays a list of recent activity. What I'd like is when the expander is expanded the window grows in size proportionally. When hidden the window again resizes proportionally. If the window is resized the expander and it's contained list view should grow to use the new space. (don't mind the colors there 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

Resized to new space

alt text http://www.deploylx.com/so/wpfexpander/Expanded.png

So far this works great. The problem comes when the <Expander /> is collapsed after the window is resized. Rather than the window collapsing again, the list view is simply hidden:

Collapsed after Resize

alt text http://www.deploylx.com/so/wpfexpander/Collapsed.png

My intuition tells me that the Height of the window is being set when the window resizes and thus overrides the SizeToContent property. So, how can I get the window to keep it's size to content behavior after it's been resized?

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="
Edit
Report

1 Answer

2

I've found that putting the body of my Window in a View and then putting the view as the sole child in the window solved similar problems...

Not the most desirable solution, but it seems to work.

answered 2009-06-11T22:17:24.583

Your Answer