Skip to main content

Microsoft Silverlight

Answered Question Set grid column width with IsStar from code behind.RSS Feed

(0)

xkrja
xkrja

Member

Member

67 points

136 Posts

Set grid column width with IsStar from code behind.

How can I set the width of a column in a grid to be 50% of the total grid width? In XAML the '*' is used but I don't understand how to set that property from code behind. Any ideas?

Thanks for help!

Please mark as answer if you found my post useful :-)

Thanks!

ssenthil
ssenthil

Member

Member

501 points

108 Posts

Re: Set grid column width with IsStar from code behind.

gridLayout.ColumnDefinitons[1].Width = double.NaN;

xkrja
xkrja

Member

Member

67 points

136 Posts

Re: Set grid column width with IsStar from code behind.

 No. Did you try this?

gridLayout.ColumnDefinitons[1].Width

is of type 'GridLength' not double. 

Other ideas anyone?

Please mark as answer if you found my post useful :-)

Thanks!

baskarg83
baskarg83

Member

Member

414 points

127 Posts

Answered Question

Re: Set grid column width with IsStar from code behind.

 Try this code

 

MyGrid.ColumnDefinitions[0].Width = new GridLength(0.28, GridUnitType.Star);
MyGrid.ColumnDefinitions[1].Width = new GridLength(.72, GridUnitType.Star);

 

i hope this will help u,  mark as answer

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities