How to get the Design time height/width of a wpf usercontrol

Go To StackoverFlow.com

1

Is there a way to get the size at runtime ?

I need to display the usercontrol in a dialog and need to size the window accordingly

Since there are multiple usercontrols, looking for make it generic if possible !!

2012-04-04 02:51
by Kumar


0

You can use SizeToContent

<Window x:Class="WindowSample.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="WPF Window"
            SizeToContent="WidthAndHeight" >

This will make your window automatically resize itself to fit the preferred size of your window contents.

2012-04-04 03:02
by surfen
looks good, will try it out - Kumar 2012-04-04 04:13


1

Sounds like you might need to rethink the problem? If you need the design time height and width, then just set the Width and Height of the control you are working with explicitly. This will 'default' the control to a specific size. Normally, you'd probably want the control's width and height to be set to Auto and have the container or layout manager decide what the size should be. So if you put the control in a Grid, assign it to a quadrant and set the size there.

Finally, if you're asking because you are designing with Blend and resizing the user control sets the design time, you can resize the control explicitly by selecting the inside corner notch instead of the outside corner notch with the bigger handle. The inside notch will result in Height and Width being set explicitly.

2012-04-04 03:00
by cunningdave
sorry the Q is perhaps not clear, I'm trying to popup a dialog window given any usercontrol as it's content, rather than set the height & width explicitly, i'd like to reuse the settings from design time, and no, not using blen - Kumar 2012-04-04 04:13
Ads