How can i make grid to behave like a window? I mean when you drag the borders you can increase or decrease the grid's height and width.
Thanks in advance :)
I am not sure to understand what you are trying to achieve here, but maybe if you to put your grid within another one and on the parent Grid, use a GridSplitter to resize the Child Grid. Here is a great example on how to use gridSplitters :
http://www.silverlightshow.net/items/Using-the-GridSplitter-control-in-Silverlight-2-Beta-1.aspx
Related
I have WPF StackPanel which I want to resize its height according to the height of its contents. Is there any native way to do this? StackPanel doesn't seem to support "SizeToContent"
Thanks in advance!
StackPanel will always grow and shrink according to its contents, but what you end up seeing could be constrained by what contains the StackPanel, such as a Window.
I'm looking at creating a panel that takes all the children and wraps them inside of a ViewBox so it can scale them down to a certain uniform size.
I'm not sure if this is even possible to do, but I thought I'd ask. The reason why I'm not sure if this is possible is because Panel's don't have any xaml associated to them. They measure and arrange children in code. Any tips?
After not being clear enough, I figure I'll be more specific:
I want a Panel because I want to arrange and measure my children.
The measure find the AVERAGE height/width of all the children elements.
The arrange puts them into a grid-like pattern and scales them to the average height/width. I don't want them cliptobounds, I want them scaled up or scaled down appropriately.
I already got the measureoverride function working to find the average height/width, but I can't figure out how to scale them in my arrangeoverride.
You haven't completely specified how you want your panel to work so I can't give you a sample panel, but I can point you to a working panel that does something similar to what you want to do:
Making a Viewbox scale vertically but stretch horizontally
In the example you can see that we can simulate a Viewbox by just scaling the children of the panel ourselves. As I mentioned, exactly how you want to scale them is up to you.
Even after your update, I agree with Markus. It doesn't seem you need a custom panel. What you need is an ItemsControl with UniformGrid as ItemsPanel and ViewBox as ItemsContainer. UniformGrid decides how your items container are arranged. ViewBox handles stretch and scale of each item.
In my case, I would like the expand/collapse to happen from left to right and right to left respectively.
The animation should happen when the visibility changes.
Thank you.
You could create two animation storyboards (One for expanding and one for Collapsing) that animates the Width of the stackpanel, then on StackPanel_VisibilityChanged run the appropriate animation.
I recommend animating on the Width property rather than ScaleX.
Otherwise the entire control (StackPanel) will look crunched/stretched as its animating.
I am trying to fill the Grid control with custom controls dynamically. After the grid is filled with elements, I need to connect these elements by lines. How do I achieve this....
Thanks in advance
I have an idea you could try: Within a Grid, items will overlap each other. So you could create an outer Grid which contains your grid and also a Canvas with a transparent background. On the Canvas, you could draw lines which would look like they are connecting your Grid's elements.
You can use a Grid set as an ItemsPanel for an ItemsControl. It's not quite easy, but if that's the way you want to go.
For connecting elements by a line, here is a good article that shows you just that:
UI Frontiers: Thinking Outside the Grid (by Charles Petzold)
Been checking the web and this site, but couldn't come up with any descent results.
Is there a way to make a canvas in WPF show scrollbars on overflow ? Been trying the scrollviewer, but can't get it to work :(
Thanks in advance..
The problem you're running into is that Canvas, unlike many WPF panels and containers, does not size to contents. That means if you add an element which goes outside the canvas boundaries it will not update it's size. Hence embedding a Canvas in a ScrollViewer will do no good unless you manually update the size of the Canvas.
It sounds like what you want is a Canvas which supports size to contents. This blog entry has exactly that control.
http://themechanicalbride.blogspot.com/2008/11/auto-sizing-canvas-for-silverlight-and.html
I took a different approach and abandoned the Canvas for Grid. The Canvas is more performant but for my purposes at least I haven't noticed a difference. The grid can mimic the behavior of canvas by doing the following.
Create a single row,single column grid.
Set the HorizontalAlignment to Left
Set the VerticalAlignment to Top
Use Margin "x,y,0,0" to set the position.
Bam..works just like canvas and it works great in a Scrollviewer.