I have a peculiar requirement related to setting width of controls in silverlight. Generally when UI renders in Silverlight, width of container control is calculated based on widths of child controls. I have a requirement where layout of the application can change drastically. One of the scenarios is that I have a Grid cotaining listboxes in each column. These column can have several user controls. Now I want to set width of user controls to expand as much as possible to stretch for width of listbox control. Is there some way to do this? If I set fixed width of user controls, it could leave some area blank on UI or horizontal scroll in listbox may appear. If I set "Auto" width of user control, there could be some unused space in UI. Is there any way to deal with this issue?
Set the HorizontalAlignment of your usercontrols to System.Windows.HorizontalAlignment.Stretch. Note that you should leave your Width unset if you do this, as it takes precedence over HorizontalAlignment.
Related
I've got a winforms application, using devexpress library. In this application I have an overview form with a list of datagrids (gridview controls of devexpress). The number of rows is dynamic, so is the number of datagrids shown. The grids are programatically added to a panel on the form.
The width of the grids need to scale with the width of the form. I managed to do that by setting the property docking to "top". The height of the grids should scale based on the rows inside. But I can't make this happen.
How can I add a grid to the panel (or form) with width set to 100% and height based to content of the grid?
Refer this - Calculate the "perfect" size/height of a Grid
The height of the grid content can be calculated via the ViewInfo
object. Follow approach from the How to change the Grid's height
according to the total height of its rows example.
In WPF Ribbon menu, width of AuxiliaryPaneContent (in RibbonApplicationMenu) is not available. How to change its width based on the items present in it?
There is no direct property to set the Width or Height of AuxiliaryPaneContent. The solution given here may help: AuxilaryPane Size.
I am having problem understanding the scrollviewer in silverlight webpage. There are the usercontrol and grid "layoutRoot". My scrollviewer is set before the "Layoutroot" grid. It never worked properly. Even though I have other items at the bottom of the page, I could not scroll to them and could not see them. I have been playing with UserControl MinHeight, DesignHeight and minHeight of both LayoutRoot and Scrollviwer. Just have a hard time figuring out what is the best way to set it up.....
You need to remove min height and max heigh from all of the control because Silverlight takes care of all those things. What you need is to set VerticalScrollBarVisiblity to auto. By default it is disabled and you will be able to achieve what you want.
Cheers!
Vinod
If the MinHeight properties are set too large then it will not be viewable on the screen and will be cut off. If you remove the MinHeight properties on both the UserControl and ScrollViewer then it should work fine.
Or if that doesn't work post your code so we can have a look.
I have an Expander control and i need to calculate its bounds without invisible elements and margins. It commonly can be done by VisualTreeHelper.GetDescendantsBounds. But it seems that the rect is calculated by VisualTreeHelper doesn't depend on the expander state. For example:
http://i.piccy.info/i5/58/39/273958/collapsed.jpg
(i can't post images. sorry)
The same result as for expanded state (light green rectangle on the image). Does anybody know how to solve this problem?
The Expander control will set its content's visibility to Collapsed, which means it won't be considered during layout and won't be included in GetDescendantBounds. However, the Expander can be forced to have a larger size by the layout engine, and the Expander's own size is included in GetDescendantBounds.
Try setting VerticalAlignment="Top" on the Expander. The default is Stretch, which will allow it to increase in size if the parent has more space available. Also make sure you aren't explicitly setting the Height property.
This is the sample application. The style is applied here to the TreeView control and its items. But the problem doesn't depend on the style.
I have read that placing a canvas inside a scrollviewer won't work because the canvas does not report its size. I have been experimenting with different containers (borders, grids, canvases and scrollviewers) and could really do with a simple explanation of how scrollviewers behave within nested containers. e.g. If I have a container hierarchy of UserControl>Grid1>Canvas1>ScrollViewer>Grid2>Canvas2 should scrollbars appear around Grid2 when Canvas2 becomes wider than Canvas1? (or indeed wider than UserControl) If not, how should I organise my containers so I can add loads of uielements to Canvas2 and have scrollbars appear as necessary. (My usercontrol width and height are set to 100%)
Canvas will work with a ScrollViewer if you explicitly give it a size. The problem comes from the fact that if you don't supply a Height and Width for any control it will try and determine it's available area based off it's parent container. A ScrollViewer however has infinite available area.
Take a Grid for example. If I define a Grid that has 2 Star Width columns and 2 Star Height rows. How does the Grid know how wide each of those columns should be? The star says they should be half of the available area, but inside a ScrollViewer the available area is infinity.
What controls are you adding to Canvas2? If you are adding them with fixed positions than the ScrollViewer will expand to house all elements. If you aren't giving them fixed positions than all the controls will stack on top of each other, because that is the arrange behavior of a Canvas