What I need to do is to stretch the control to fill entire Canvas.
I think I have to use a Canvas (I don't want my control to be clipped
when rendered outside the container - as far as I know all the other containers
perform clipping - Grid, Border... - maybe there is another solution?)
If I put the control inside Canvas it works fine (I mean it is not clipped).
However, it doesn't fill entire Canvas.
I was trying to bind to the Canvas width and height - with no results.
Do you have any ideas or clues?
Thanks in advance!
A control can escape the container such as a Border or a Grid by having negative margins. So perhaps you should return to using a Grid and play around with placement using column and row definitions and using negative margins where you need them.
Related
I've got a ScrollView inside my Canvas which will be populated with a UI GameObject (Panel) at runtime. Because this dynamic child does not have a fixed size, I want to resize my ScrollView to the same width as the child. In other words: The ScrollView should be the width of it's child.
I think this is possible without the need of coding but I cannot get it to work properly.
I already tried to add a Content Size Fitter to the Content, Viewport and ScrollView, but this only results in a width of 0.
My structure is the following
Please tell me if you need some more information
Edit 1:
it seems like the problem is with the GameObject Content. It does not resize with it's child element
The only object that shouhld have ContentSizeFitter is the Content of the scrollview (only in the axis you want the content to expand). To work properly its best to also have a Vertical or Horizontal layout group, with checkboxes 'child control size' checked, and 'expand' un-checked.
No all thats left to do is make sure all the children of the content object have LayoutElement with preferred layout sizes.
It can be a little bit tricky to get it right first few times but definitely possible. The order in which you add components is somewhat important : make sure you have layoutElements set up in the children first, then add the layout group, and only after it works correctly add the content size fitter. If you do it the other way around it tends to escape, as in you mnight get objects resized to 0 before you notice
Fore note: I know you cannot use a margin with dock, but I am trying to figure a way around this.
I have two objects, a GroupBox (containing loads of buttons and stuff that will always be the same size no matter how big / small the form) and a WebBrowser. The former will take up roughly 100 pixels at the top, and the latter will take up the rest of the space. I have tried multiple ways to get around this, including Panels, GroupBoxs, changing Anchors and Docks, but nothing is working. I know there is a simple solution for this, but I cannot work it out. Could someone point me in the right direction for what I should be using?
P.S. New to WinForms so not very knowledgeable of things.
Start with a TableLayoutPanel control on your Form and set its Dock() property to Fill. Now change the ColumnCount() property to 1, and leave the RowCount() property at 2.
Add your GroupBox to the Top Row and adjust its size. Add your WebBrowser control to the Bottom Row and set its Dock() property to Fill.
Finally, select the TableLayoutPanel, find the Rows() property, and click on the "..." dots to the right. Select Row1 and change its Size Type to AutoSize.
Done!
Alternative Approach...
Add your GroupBox to the Form and set its Dock() property to Top. Add your WebBrowser control and set its Dock() property to Fill. Note with this approach, however, that the GroupBox will extend to fill the full width of the Form.
I have two controls in a groupbox ("Waveforms"). I would like them to dynamically resize also by height but can't get it to work. I've used left|top|right anchor for 1st control ("Left channel") and left|bottom|right anchor for 2nd ("Right channel").
Here is a short video of problem.
How can I acomplish this?
If you want your controls to share vertical space of the GroupBox, you can use a TableLayoutPanel or a SplitContainer.
By using a TableLayoutPanel you can easily specify how the vertical space should be shared by controls. For example you can add two rows to the TableLayoutPanel and give them each 50% of the whole height.
By using a SplitContainer, the user can change the occupied heights of the controls at runtime.
I'm creating a Windows 8 Metro app. I have a TextBlock in a ScrollViewer. I'm wondering if it possible to programmatically change the ZoomFactor of the ScrollViewer to make the TextBlock auto-fit the width of the screen. Meaning, the longest line of the TextBlock fit the screen width (without wrapping).
Generally I find ViewBox to be the most useful way to scale xaml contents to fit a predetermined size. Simply leave your ScrollViewer and TextBlock with no size requirements (and turn wrapping off) and then put the ScrollViewer inside a ViewBox with Scale=Uniform (or possibly UniformToFit depending on your needs).
The TextBlock will cause the ScrollViewer to size appropriately for its contents, and then the ViewBox will scale the ScrollViewer to exactly fit in its own control extents. (Putting the ViewBox inside your root grid or as the root control of your page should cause it to fill the entire screen.)
I am dynamically creating data grids in a tab window in WPF. I am having an issue with the data grid sizes, that are within the tabControl.
This is not an issue of the size of data within the data grid but the size of data grid itself.
I am looking to set the height and width to auto. This is simple in XAML but I am struggling to find any information to do it in the code which I need to do..
I have tired double.NaN but this does not seem to work....
Any help would be amazing!
I am using c#.
Try
Height = new GridLength(1, GridUnitType.Auto);
The problem is probably the StackPanel. It won't give the controls inside of it any more space than they "need" in the direction of it's orientation (so a vertical stack panel will only give the minimum required vertical space to each element). Try replacing it with a Grid or DockPanel.
In other words - controls in a vertical StackPanel will NOT expand to fill available vertical space, similarly for a horizontal StackPanel.