I have a TabControl consisting of several TabPages. One of these TabPages contains a TreeView and another contains a DataGridView. I would like these controls (and tabpages) to AutoSize to the maximum size allowed in the TabControl without scrolling.
The DataGridView contains an AutoSize property inherited from Control which garbles the control if enabled. The TreeView does not have this property. I have tried setting the Size equal to TabControl.Size but that does not account for bordersize and the Tabbar height.
treeView.Size = new Size(tabControl.Size.Width - SystemInformation.Border3DSize.Width * 2, tabControl.Size.Height - SystemInformation.Border3DSize.Height * 2);
My question is: how can I determine the height of the Tab buttons or how can I automatically fill TabPages to their maximum size with a single control?
The Property you search is called Dock.
You probably want to set it to DockStyle.Fill on your TreeView and DataGridView.
An alternative would be to set the Anchor Property to AnchorStyle.Top, AnchorStyle.Left, AnchorStyle.Right and AnchorStyle.Bottom (concatenate with binary OR the pipe sign '|').
For that you would need to set the size of the Children to ClientSize
Related
I have a ContentControl that swaps out views based on a 'CurrentPage' property chosen in the ViewModel.
I'm using a Window to host this ContentControl - it contains UserControl views and acts a persistent View/ViewModel for the application.
How do I bind the size of the Window to the size of the currently displayed content?
You don't need to data bind the size of the Window to its content. There is a property called Window.SizeToContent that will have the same effect. From the linked page on MSDN:
Gets or sets a value that indicates whether a window will automatically size itself to fit the size of its content.
A typical example of its use would be this:
// Automatically resize height and width relative to content
this.SizeToContent = SizeToContent.WidthAndHeight;
Im writing a WPF application where usercontrols are added to a TabControl at runtime - creating a tab for each user control. The problem then is...these controls can have different width and height which means the tabcontrol must adjust its own width and height accordingly. I tought this would be a simple exercise of just accessing the usercontrols Height/ActualHeight properties, but these are NaN/0.0
Is it not possible to get this information?
I can propose next solution:
When you add a new control to the TabControl (is it a TabControl or a TabItem?) set bindings for the Width and Height properties. Create a converter to convert sizes of added controls to the size of Owner (in case if you need to have minimum size).
ActualWidth and ActualHeight properties perhaps are 0 because control wasn't measured yet. Look this thread
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 have to develop a control having one datagrid. now datagridtextcolumn have to be binded with one property of collection created in viewmodel.
based on data i have do one thing...
if for a row no of lines is more than 3 in last column's cell then show a button having text "More" with last cell else with text "Less" and on click of "More" button it should display full text data...
now this layout can be shrined as well as stretched at runtime according to window's height and width using viewbox control or any other way...
so how to achieve this thing any idea???
Basically you want a custom textblock control that displays a max of 3 lines and shows a more button (if there are more than 3 lines of text)*.
The more button expands the textblock and I imagine stays around to collapse it again?
As it sounds like you only have one column (more like a list), rather than customise the datagrid create a usercontrol (with a grid, textblock and button) that does what you want and bind that inside a templated column instead.
You will need to expose the Text property as a dependency property for it to bind to. Most of the details of creating this type of usercontrol are on my answer to this: putting Button inside a TextBlock(or maybe something else) to make it work like the one on video?
Just add your size logic and change the layout to suit your needs.
*Note: Personally I would use the MinHeight property of the usercontrol to set when the "More" button is needed, then it will be more flexible, but that is just a suggestion.
I'm working on a UserControl that consists of a bunch of ComboBoxes arranged horizontally across the top of the control in a flowlayoutpanel, and a datagridview directly below the flowlayoutpanel that takes up all remaining space on the control. I need to be able to hide all the dropdowns easily, so I have a SplitContainer with Orientation == Horizontal, with the flowlayoutpanel in SplitContainer.Panel1, and the datagridview in SplitContainer.Panel2.
The control hierarchy is as follows:
SplitContainer1
SplitContainer1.Panel1
FlowLayoutPanel1
ComboBox1
ComboBox2
ComboBox3
SplitContainer1.Panel2
DataGridView1
Since the flowlayoutpanel is oriented horizontally and horizontal space is limited, the flowlayoutpanel's WrapContents property is True, so that the dropdowns wrap down to the next row when the control is made too narrow to fit all the dropdowns in one row.
The problem I'm having is that when the flowlayoutpanel wraps its contents down onto the next row, its Height property does not change accordingly. The wrapped rows of the flowlayoutpanel are clipped, and don't force the splitcontainer panel to grow in height accordingly. I've tried to handle the FlowLayoutPanel.Resize event to grow and shrink the SPlitContainer.SplitterDistance property to accommodate the wrapped contents, but the FlowLayoutPanel.Height property does not change when contents are wrapped. I'm stumped. Is the FlowLayoutPanel broken? How can I resize the FlowLayoutPanel's parent container if FlowLayoutPanel.Height always remains the same, regardless of content wrapping?
Thanks
It seems like you're making this a little too complicated for what you need. You can use the built-in docking to accomplish what you want without using the SplitContainer. Set up your form like this instead:
FlowLayoutPanel1 (Autosizse = true, Dock = Top)
ComboBox1
ComboBox2
ComboBox3
DataGridView1 (Dock = Fill)
Then when you want to hide FlowLayoutPanel1 you can just toggle the Visible property to hide/show it.