Let's say I've a grid and some images which I want to show. What I want to do now is putting the images in a straight row. If they don't fit inside the grids width anymore, they shall be put in the next row. I feel like there has to be a way to do that automatically, like the LayoutManager in Java for example. Any ideas?
You should use wrap- or a stackpanel inside your cell and set some alignments (for example set verticalAlignment to "strech").
http://www.wpf-tutorial.com/panels/introduction-to-wpf-panels/
Related
I have a WPF DataGrid with many text cells per row. Currently the DataGrid will draw a horizontal scroll bar and make me scroll horizontally to see all the content.
I simply want to automatically size the columns in such a way to fit all within the current window or screen. I don't care if the text wraps, that's totally fine--in fact I've already set text wrapping and it works great if I manually shrink the columns. Even if I just made every column the same size, that's fine so long as they all fit on screen without the need for a horizontal scroll bar.
I've searched for a while and seen endless ways to resize content which don't apply to what I'm trying to solve. I'm fine using code-behind if needed, by the way.
The solution, since I'm required to use code-behind for my project, was to set the Width of each column to new DataGridLength(1, DataGridLengthUnitType.Star); I can adjust based on individual cell contents later.
Thank you, #chancea.
I had created a grid(silverlight5) by doing this Grid bigGrid = new Grid(); using silverlight.
Then i assign it 3 columns and 7 rows in it.
Now each cell has a textblock. And it works fine.
I have to create opacity on any particular row of this already existing grid (bigGrid).And this particular row will be decided dynamically.
How to achieve this in c# code ?
I mean i need something like :
bigGrid.row[particularRow].Opacity=true; (could someone please correct me ?)
I can think of two ways to achieve this.
First, you can't simply set a row(RowDefinition)'s Opacity, because RowDefinition is not a UIElement. What you can do is that you set the Opacity all the elements on this row to 0. In your case the elements would be 3 TextBlocks.
Also you can create a Rectangle on top of the entire row (RowSpan of 3) and set its Fill color to match your Grid's color as well as its Opacity to 0. When you want to hide this row, simply set the Rectangle's Opacity to 1 to block the visual of the TextBlocks.
We need to show our disabled comboboxes as an image. The image has the same height as the standard combobox, but for some reason it cannot override the borders of the combobox.
Instead, it end up looking like this:
We would like them look like this image, i.e. that the image is shown on top of everything - including the combobox borders:
Any ideas?
Thanks.
First of all, what you are trying sounds really dirty - the best way would be, if your ComboBox would just look like your image as soon as you disable it!
If there is really no other way:
Create a PictureBox in front of your ComboBox. Set the image as the PictureBox's image, make it Visible whenever you want to "disable" your ComboBox.
But again, using controls to simulate behaviour you would expect to be part of another control is dirty.
Get the location of you textbox, set it invisible, then a the same location place an imagebox
I want to make it so that my buttons change size based on the text inside them. Kind of like a Label with it's height and width set to "Auto", but I would like to start with a pre-determined dimension.
Is there a way to place a button, size it, and allow for re-sizing based on run-time text changes? If so, how do I do this?
I've looked at this example:
http://social.msdn.microsoft.com/Forums/vstudio/en-US/188c196e-90d8-4584-bc62-38d7e008cf5c/how-do-i-resize-button-text-upon-button-resize
It has to do with inserting a textblock on top of the button, but when the text adjusts sometimes the new text becomes too small because the text does not wrap for some reason...
Thank you.
You can set the MinWidth and MinHeight properties so that you start with a predetermined size and the button will be able to grow with text.
Unfortunately this would not allow the button to get smaller.
You will need to size it based on its content, then. That is, have no XAML defined size.
Elements on the page normally size themselves to their children.
Just ran into a bunch of random but probably very simple questions while learning to work with WPF. If anyone can answer any of these it would be most appreciated.
I have a Rectangle that I styled to my liking, and then a StackPanel that I am actually placing the content (bunch of labels) in. It looks like Rectangle doesn't have a closing statement so how can I make it the parent of the StackPanel (I want the panel to move with it)?
I need to display text (labels) in a table form. It will only be two columns, and 8 rows (row count may change). I initially looked into just using a Grid, but as this is a intended for Layouts, it didn't work as expected. I also checked out DataGrid, but this seems confusing and overly complicated for my needs. Is there any simple Table style element I can use?
I have some Animated Expanders and I want to give the other UI content elements in my application a similar looking title bar. I haven't seen any sort of element for this, so I am wondering if I just need to use a Label or something and style it as close as possible to match, or if something already exists that I should use instead. If I need to use a label, what is the proper way to group/attach it with the element that it is the title bar for?
Do any controls exist for WPF that would allow for a Mac style menu bar? Something similar to where the icons move and expand as they are mouse over.
I have a grid that has two expanders (one above the other) with Height="Auto", and two rows set to Height="Auto" so that when the top is minimized, the bottom one moves up to close the gap. I am using a MinHeight right now to make sure they are at least somewhat expanded, but I would like to make them take up the full 100% of the Grid height. What should I do for this?
A rectangle cannot have child content, a better approach might be to use a Border, you can use this as that parent of your stackpanel, applying a Background and BorderBrush to make it look like a rectangle.
For a simple table layout Grid is the way to go. Is your problem that you need it to be dynamic? If so, you can create multiple grids with SharedSizeGroup on the columns to make them look like a single grid. See: How to align separate Grids created via templates along their columns / rows?
Learn about creating your own templates!
Not that I know of, but it would be relatively simple to do, create a storyboard that scales the item on mouse over.
No idea ... running out of steam!
As Andrzej Nosal mentioned, these really should be separate questions!