tags:

views:

421

answers:

2

Hi,

I would like an expanding panel in my Windows Forms app. I was having a look to see if this would be possible using the WPF Expander control. I've created a Xaml UserControl where I've inherited from Expander rather than UserControl. I have a trigger on the Expander for setting it's size.

Is it possible to change the height of the ElementHost to reflect the change in the size of the child? Or would I just be better off creating an expanding Panel in Windows Forms?

I'm using C# .Net 3.5.

Cheers

A: 

Is there any particular reason you are inheriting from Expander vs. just using an Expander in your UI?

If you set up the H/V Alignment properties of the Expander, you should be able to get most standard sizing behaviors without having size triggers. From my experience, the content portion of the Expander automatically sizes to fit.

If you're trying to completely remove the header part, then you might look at making your own ControlTemplate for the Expander.

micahtan
A: 

Yes. You need to override MeasureOverride in your outermost WPF control, convert the size from WPF coordinates to device coordinates, and update ElementHost.Size.

Since you are already subclassing Expander:

  1. Override the MeasureOverride method
  2. After the measurement is calculated, use PresentationSource.From(visual).CompositionTarget.TransformToDevice.Transform(point) to get the device coordinates
  3. Update ElementHost.Size.

Your Expander subclass instance will need a pointer to ElementHost to do this.

A more general solution would be to create a new class to handle the synchronization. It would subclass FrameworkElement and be the direct child of ElementHost.

Ray Burns