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.
Related
I have a list of controls, put into a stackpanel. These controls are Hubtiles, that are added programatically after a user creates it - a list essentially. I need to make the StackPanel in which they are added, scrollable - what would be the best approach for this? Should i put the stackpanel inside a ScrollView, and then increase the StackPanels height with the actual height of the Hubtile - to make it scrollable, but not so that the user can scroll infinite without something being there. So whenever the amount of controls inside the StackPanel reaches 3, it'll automatically increase it's height like this:
Whenever the amount of controls inside the StackPanel reaches 3 or above:
StackPanel.Height = StackPanel.Height + Hubtile.ActualHeight;
Thanks a lot!
Just put the StackPanel into ScrollViewer, set the StackPanel.VerticalAlignment to Stretch and set fixed size to the parent ScrollViewer. This is necessary - the ScrollViewer must know its size, to show the scrollbars for the inner content when the inner content is too long.
I've got a DataGridView with the RowHeaderVisible property set to false;
I have the margins and padding set to 0;
then the size is equal to the header widths added together...
Why is there extra space still needed to show the full control? (There is a horizontal scroll bar visible) What property does this, or how would you get an accurate measurement of the exact (actual) sizing of the control?
I havent used one for a while but if its like a listview, the headers should be less than the width to leave space for the vertical scrollbar - presuming you have one. Try reducing the width of one of the headers, or increasing the control width
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.)
Currently I have some GridViewColumns that use Auto for their Width property, but this only seems to work on startup. After I add new values to the ListView, the GridViewColumns using Auto don't adjust their width.
Any idea on how to do this?
Wrongly understand your meaning ;(
you should set the width by code
Here you are: How to autosize and right-align GridViewColumn data in WPF?
fire it up to blend to ease your design process,
or click off the clips with "8" signs
then it will not drag follow with the size of window (in total of 4 clips and 4 sides)
also make the horizontal scroll bar become visible, then it will add up value and scrollable =D
What are the other columns sizes set to? If they are fixed then the Auto sized column will only be able to grow up to the maxwidth minus those column widths. Have you tried setting their column sizes to *?
-Matt
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.