Invalid location of GroupBox with FlowLayoutPanel inside - winforms

I have such form layout
Panel Dock=Fill
GroupBox Dock=Bottom
FlowLayoutPanel
Panel
Panel
Panel
Panel
Panel
Panel
(as shown here https://onedrive.live.com/redir?resid=8664902FAE855051!64006&authkey=!AAy9OiMaSwqs2Fs&v=3&ithint=photo%2c.png)
When I resize the window the layout of 4 Panels inside FlowLayoutPanel is changed incorrectly - last Panel is placed out of GroupBox (https://onedrive.live.com/redir?resid=8664902FAE855051!64005&authkey=!ANnpm-6d3RAKa_M&v=3&ithint=photo%2c.png)
It seems that GroupBox has invalid value of Location.
But if I resize the GroupBox once more, everything is ok and all Controls are placed inside the GroupBox
AutoSize properties of GroupBox, FlowLayoutPanel and all Panels are set to true.
Could anybody help me to solve this issue?

Related

Padding for WinForms TreeView

In a WinForms application I have a custom button positioned on top of a TreeView. In certain scenarios the button will hide the bottom content from the TreeView:
I'm looking for a way to invisibly inflate the TreeView-height in the bottom in order to trigger the scroll bar earlier, and am open for other suggestions, too.
I have done a similar thing with buttons at the top:
I used a UserControl with a TreeView docked to fill and a Panel docked to the top. (In your case, dock the panel to the bottom.) I set TreeView.BorderStyle = None and used another Panel to look like a border with 1px padding all around, which hosts the button panel and tree. You can make the tree public or expose it via a property. With docking you can also hide the button panel as necessary, and the tree will automatically take up the remaining space. I also used a Label docked to the bottom inside the button panel to act as a visual separator.

TreeView children's margin in WPF

I'm writing the WPF app that uses TreeView control inside the UserControl. TreeView control has the same width as the UserControl.
The problem is that I need to make the children nodes to have the full with of the TreeView. I can't assign the width by the static expression as well as UserControl that contains TreeView may have variable width.
I thought that the solution can be reached by assigning the TreeView child item the width of the UserControl. But if I do so the TreeView child item will be out of control, as well as there is margin in the children item. For example
Item A
---Item B
Can you tell, how can I get the width of --- ? Or to make ItemB be under the Item A without using static margin metrics?
Thank you
You can edit the Style of TreeViewItem and make its Horizontal Alignment as Stretch instead of Left. Also ensure you host your ContentPresenter inside the Grid.
In this case, eventhough the header text seems to be leeser in width, the mouse hover or Selected color will cover the entire width of treeview. I hope that is what you need.

Docking of Silverlight Controls

I've read this question, but still, it explains how to dock controls within DockPanel. How does one dock the DockPanel within the window?
As you can see, the Map control is docked to the DockPanel, but the DockPanel is not docked to the window.
What am I missing?
Remove HorizontalAlignment and VerticalAlignment properties from the DockPanel, the default for these properties is Stretch which will cause the DockPanel to fill the available space.

How to make the content of Expander visible to VisualTreeHelper

I've put an Expander onto a Page. Within the expander there is a Label. After the page is loaded, the expander is not yet expanded. At this point, I inspect the Expander using VisualTreeHelper, I got a structure like this:
Expander
Border
DockPanel
ToggleButton
Border
Grid
Ellipse
Ellipse
Path
ContentPresenter
ContentPresenter
where there is no Label under the last ContentPresenter.
However, Once the expander is expanded and then collapsed, I got the a different structure using VisualTreeHelper:
Expander
Border
DockPanel
ToggleButton
Border
Grid
Ellipse
Ellipse
Path
ContentPresenter
ContentPresenter
Label
Border
ContentPresenter
This time, the Label appears under the ContentPresenter.
It seems that as long as the expander has been expanded, VisualTreeHelper will know the contents within the Expander. But is there a possible way to make VisualTreeHelper be aware of Expander's contents without expanding it?
Thanks.
There is a method for forcing a control to load its contents programmatically.
I imagine you have some sort of recursive loop that searches through your elements. Before you call to get its children, use this call:
if (element is FrameworkElement)
(element as FrameworkElement).ApplyTemplate()
That'll force it to apply its template and load the controls into memory. I imagine it is done this way for performance reasons, as controls are not normally needed until they are visible.
This approach also works for TabControl and any other control that can hide content, I believe.
Credit goes to Tao Liang who posted this solution over here. Read it also if you're having trouble with your recursive loop.

How to adjust the height of the window dynamically in WPF?

I have a model window that contains expander control.
This expander control when expanded shows the user control which allow user to enter input through textboxes.
When expander control is collapsed it hides the user control.
I want when expander is collapsed or expanded the window will resize its height accordingly at run time.
Pleas help!!
You can set property SizeToContent="WidthAndHeight", see also on SizeToContent on MSDN

Resources