Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have text boxes and labels on grid
and all are on window in wpf application.
.
i have set all positions and margins of controls, but when i change grid size, then why control size get changes automatically ??
.
i dont want that, what should i do ??
.
i need help..
Posted
Comments
[no name] 23-Sep-14 7:48am    
"control size get changes automatically", because that is what it is supposed to do. If you want to limit yourself to a bad design in WPF then use a canvas.
Sergey Alexandrovich Kryukov 23-Sep-14 14:28pm    
Basically, a good point. But not always. Quite certainly, some controls should never be resized. Please see my answer.
—SA

Please see the comments to the question, by Wes Aday and mine.

Short answer: you need to use one of the most practically important XAML attribute value strings: "Auto". If you have a row definition with Height="Auto", its actual height will be defined by the content's controls; if you have a column definition with Width=Auto", its actual width will be defined by controls. Other width/height definitions give more complex behavior.

Background:

In WPF layout, there are too opposite approaches: ether the size of the content defines the size of the controller, or the size of the controller defines the size of the content (if it even fit, but it also can be scaled to any size). Here, by "container", I mean some Panel (Grid is also a Panel) or Window (System.Windows.Controls.ContentControl). The choice is independent for horizontal and vertical direction.

So, the whole behavior will also depend on the Window property SizeToContent:
http://msdn.microsoft.com/en-us/library/system.windows.window.sizetocontent%28v=vs.110%29.aspx[^].

—SA
 
Share this answer
 
Comments
Madhuri Gamane 24-Sep-14 0:32am    
sorry, but i don't got your ans..
Sergey Alexandrovich Kryukov 24-Sep-14 1:27am    
I'm sorry, too, but how can I help you if you did not explain what part of it you cannot get? You need to be familiar with the basics well enough to be able to understand so simple answers...
—SA
Madhuri Gamane 24-Sep-14 3:33am    
I haven't create any row and column defination.
but place all controls, i.e labels and textBoxes Directly on grid control
Sergey Alexandrovich Kryukov 24-Sep-14 3:57am    
This is no good. Don't do such things.
—SA
First Give the Fixed Height and Width to your Controls, which are added that grid. Do not set Alignment Properties to "Stretch" .
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 23-Sep-14 14:29pm    
Really, really bad advice. It would screw up a fixed-size control, because — how do you know that fixed size? Did you ever tried to solve such problem yourself?
Sorry,
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900