teenup
teenup

Reputation: 7667

How to constrain the width and height of <Border> element to be equal to its inner contents?

<Grid x:Name="mainGrid">
                <Border BorderBrush="Black">
                        <Grid Name="detailGrid">

Here, the detailGrid and its border takes complete Width and Height, as available from the outer mainGrid, where as the contents inside the detailGrid are having Width and Height that is much much lesser.

How can I constrain the Width and Height of Border or/and detailGrid to fit to its contents, so the the Outer Grid's background is visible ?

Upvotes: 2

Views: 3264

Answers (2)

Leo
Leo

Reputation: 7449

Set the border and the inner grid HorizontalAlignment and VerticalAlignment to Center. (or just the border should do it)

Upvotes: 8

Dummy01
Dummy01

Reputation: 1995

If your user control has defined Height and Width properties remove them.

Then define ColumnDefinitions and RowDefinitions for your Grid and set their Height And Width to Auto.

Upvotes: 0

Related Questions