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.
Related
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?
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.
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.
Can we give the space between two controls in a stackpanel in WPF?
Use the Margin property on the controls that sit in the StackPanel.
I have a WPF UserControl (Foo.xaml) that should be displayed streched (VerticalAlignment="Stretch" HorizontalAlignment="Stretch") on a window.
If I don't specify Width/Height on the UserControl it will be displayed as intended at runtime. Unfortunately the VS WPF designer will not show the control correctly if I open Foo.xaml (size may be 0x0 depending on the child controls).
If I specify a size on the UserControl the designer will work correctly with Foo.xaml but then it won't strech at runtime.
How can I fix this so that it works at design and runtime?
It sounds like your UserControl is only useful if it is a certain minimum size. If so, set the MinWidth and MinHeight properties.
You can set the DesignWidth and DesignHeight properties on the UserControl to adjust the height and width of the control in the design view.
You can adjust those properties with the mouse by dragging the square rectangles that show up when you select the resize tool for the UserControl.