Resizing elementhost is causing flickering - wpf

I use an ElementHost control to integrate Wpf into a winforms application. I have created a "kind" of step by step set of screens similar to a wizard with next and back buttons among others.
Windows Form ---- ElementHost ---- Wpf
When I go through the different screens, i am not closing and opening a new window again, instead I simply keep the same window already opened and I change only its content. The problem of this is that the elementHost is not resizing to fit its content height, neither if the content height is decreased or increased (caused by for example an expander collapse or expand or some other control). Instead the elementhost keeps always the height that was taken the first time it was open.
The elementhost has set its properties correctly, AutoSize = true and Dock to Fill. And the Windows Form where the elementhost is, also has AutoSize set to true correctly.
So in order elementhost resizes, what I do is to "force" the elementhost to resize by doing the following on each transition between screens:
System.Drawing.Size eh = myElementHost.Size;
ElementHost.SuspendLayout();
ElementHost.AutoSize = false;
ElementHost.Size = new System.Drawing.Size(eh.Width, eh.Height);
ElementHost.AutoSize = true;
ElementHost.ResumeLayout(true);
This trick causes elementhost to resize to fit its content height but.... it is causing flickering.... also for example, each time I click on the toggle button of an expander to collapse or expand it or do something in the content that cause it to modify the content height, I need to call above piece of code to force elementhost to resize correctly to fit its content height but again, it is causing flickering, so how can avoid flickering in this particular use case?

Related

Animation for SizeToContent resizing

In WPF window, I have specified SizeToContent="WidthAndHeight".
I have a number of panels stacked up, of which I change the visibility (to Visible or Collapsed) as required. My window resizes itself according to the panel that I have set visible. No issues here.
My problem is with the resizing, that the window resizes with a jerk to the final size.
I want to animate this such that the resizing is smooth. And i want to do this in my XAML file.
Is there any solution for this???
P.S. - I have not set any Width or Height property in the window and I want to restrict myself from doing that.

How to specify z-index for a panel

Hi I'm new to WPF and I want to place a Panel upon a StackPanel and show and hide it in my window without using Canvas and changing positions and size of other controls or the window.
Something like the fallowing image which the solution explorer is opened on another Panel, and as we see the user even can change the position of the Panel.
If you have a Grid as the Root Layout and a StackPanel on that, you can still use Canvas.
Canvas.SetZIndex(<YourPanelYouWantInFront>, <LargeValue (100)>);

childWindow Full Screen Event tweak the Parent to also FullSCreen Mode

I have a ChildWindow which contains a ExpressionMediaPlayer inside it. When I click on the ChildWindow Media Player Full screen button it swiches the whole application to FullScreen Mode.
Is there a way to avoid it. I am not quite sure if this scenario is going to fall under SL security restrictions.
When I drag the ChildWindow(the position of ChildWindow changes) and click on the fullscreen
now the ChildWindow also changes it's position.
For example if I have dragged the ChildWindow 50px from Top and pressed the Full Screen button of of mediaPlayer (it contains) the Child Window also appears 50 pixels below the Screen Top.
But I want My ChildWindow to be FullScreen without having any Gap from LEFT,TOP,RIGHT or below.
Any help will be greatly appreciated.
Thanks,
Subhen
Silverlight only uses one of its two windows. The first is the normal window embedded in the Host application such as IE (or in windowless mode it co-operates with the host to draw directly on one of the host's windows in a give rectangle). The other window is a Fullscreen one.
When in full screen mode it moves all its rendering of its stack of content to the full screen window. You can't get Silverlight to render only some controls on the Fullscreen window, its an all or nothing proposition.
Creating a "fullscreenable" ChildWindow would be an interesting exercise. Probably a new templated control based on Childwindow with a new "Fullscreen" visual state (in a new state group) that hides the chrome and causes the content grid to stretch with Auto Width and Height.

WinForm designer and right snapline for controls in container when resizing it

Using Visual Studio 2008 WinForm designer, I have a container (form, panel, groupbox, whatever) and some controls in it.
The container is set to not automatically resize or dock in any way. When placing a control in the container I can use the snaplines to help in positioning the control.
However, the snaplines does not appear when I resize the container to the edge of the contained controls...
Is there a simple way to have the designer show me the snaplines of the contained controls when resizing the container?
The designer will only show the snap lines when moving a child control within a container. You can demonstrate it by moving a GroupBox around a Form and see that it shows snap lines when the GroupBox gets close to the edge of the Form, but if you were to resize the Form you won't see the snap lines appear.
If you're just looking to get all of the controls to line up in a uniform fashion, I'd suggest switching to SnapToGrid mode and using the grid lines to align your controls. You can set the SnapToGrid mode by going to Tools->Options->Windows Forms Designer->LayoutMode. Open your designer and you should see the grid appear, after that you can line your controls up with the grid.
After setting the layout of the form, you can also set anchoring property to all child controls appropriately, to right and bottom (or top and left), depending on the resizing you are making. Anchor property will hold child controls to same distance from the edges of the container (parent control).
In the WinForms designer, there is no support for snaplines when resizing the container control. The best way to work around this issue is to first size the container to the size you would like to use and then add controls. Optionally, you can change the Margin property of the container so that when moving controls inside the container, they will snap to the margin of the container, keeping it uniform.
Try:
container.AutoSize = true
container.AutoSizeMode = GrowAndShrink
container.Padding.All = 5

How to make WPF WebBrowser grow horizontally and vertically?

In WPF, we are using a WebBrowser control to view HTML content. When we place the control on our window, it grows horizontally with the window as it grows/shrinks. However, we have not found a way to make the control grow vertically with the window. We are looking for some sample code that will allow the WebBrowser WPF control to grow both vertically and horizontally with the window.
With WPF and wanting to grow with the window, the magical starting point is to set the Margin to 0 and avoid setting width and height. (You can have margin equal to another number, but start with zero and see how it looks first!)
Another option is to use a dock panel with last child fill set to true, where the web browser control is the last element (as you read down the page - it doesn't have to be the last element in the rendered UI.

Resources