Friday, September 7, 2012

Setting Width of control relative to screen resolution in silverlight

Setting Width of control relative to screen resolution in silverlight

I am unable to set the size of border control relative to screen resolution. I want to specify width of Border to 80% of the screen resolution [width wise only]. But I am unable to do so.

Any help will be appreciated.

Thanx in advance.

Uday Gupta

Answers & Comments...

Answer: 1

The easiest way would be to put your border in a Grid:

<Grid x:Name="LayoutRoot"         Background="White">     <Grid.ColumnDefinitions>         <!--80% column-->         <ColumnDefinition Width="8*"></ColumnDefinition>         <!--20% column-->         <ColumnDefinition Width="2*"></ColumnDefinition>     </Grid.ColumnDefinitions>      <Border Grid.Column="0"             Background="Red"></Border>     <Border Grid.Column="1"             Background="Yellow"></Border> </Grid> 

EDIT:
Sorry, I just realised I did not read your question properly. You are talking about screen resolution. My example sets the first column of the grid to 80% of the browser window size. If it is screen resolution you want I think you will have to use javascript to get the values and then use code to set your object to the correct size:

var width= HtmlPage.Window.Eval("screen.availWidth"); var height= HtmlPage.Window.Eval("screen.availHeight");  
by : Henrik Söderlundhttp://stackoverflow.com/users/250605




No comments:

Post a Comment

Send us your comment related to the topic mentioned on the blog