locked
Setting Dynamic width of a Grid RRS feed

  • Question

  • Hi,

    I am using the following code but still my Grid is not getting streached, my grid size doesnot change as per resolution, can anyone tell me whats wrong with my code.

    <Grid x:Name="grdTest" Background="#e2e7f2" ShowGridLines="False" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="Auto">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="20"></RowDefinition>
                            <RowDefinition Height="5"></RowDefinition>
                            <RowDefinition Height="25"></RowDefinition>
                            <RowDefinition Height="25"></RowDefinition>
                            <RowDefinition Height="25"></RowDefinition>
                            <RowDefinition Height="25"></RowDefinition>
                            <RowDefinition Height="60*"></RowDefinition>
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"></ColumnDefinition>
                            <ColumnDefinition Width="Auto"></ColumnDefinition>
                            <ColumnDefinition Width="Auto"></ColumnDefinition>
                            <ColumnDefinition Width="Auto"></ColumnDefinition>
                            <ColumnDefinition Width="Auto"></ColumnDefinition>
                            <ColumnDefinition Width="Auto"></ColumnDefinition>
                            <ColumnDefinition Width="Auto"></ColumnDefinition>
                            <ColumnDefinition Width="Auto"></ColumnDefinition>
                        </Grid.ColumnDefinitions>
    <sdk:Label Content="Test" Grid.Row="2" Height="23" HorizontalAlignment="Left" Margin="4,2,0,0" Name="lbTest" VerticalAlignment="Top" Width="120" FontWeight="Bold" Grid.RowSpan="2" />
    </Grid>
    Monday, December 12, 2011 9:54 AM

Answers

  • As far as I know,If you change the display resolution,the silverlight plugin will not be notified. So you should try another way.

    you can get the resolution by javascript:

    var width = screen.width;
    var height = screen.height;

    Then you can call silverlight method by javascript to change the scale of your grid

    Wednesday, December 14, 2011 8:45 PM

All replies

  • try to use star (*), it will take the width and height as per monitor resolution, something like this.

    <Grid x:Name="grdTest" Background="#e2e7f2" ShowGridLines="False" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="Auto">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="2*"></RowDefinition>
                            <RowDefinition Height="*></RowDefinition>
                            <RowDefinition Height="4*"></RowDefinition>
                            <RowDefinition Height="5*"></RowDefinition>
                            <RowDefinition Height="5*"></RowDefinition>
                            <RowDefinition Height="5*"></RowDefinition>
                            <RowDefinition Height="6*"></RowDefinition>
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*"></ColumnDefinition>
                            <ColumnDefinition Width="*"></ColumnDefinition>
                            <ColumnDefinition Width="*"></ColumnDefinition>
                            <ColumnDefinition Width="*"></ColumnDefinition>
                            <ColumnDefinition Width="*"></ColumnDefinition>
                            <ColumnDefinition Width="*"></ColumnDefinition>
                            <ColumnDefinition Width="*"></ColumnDefinition>
                            <ColumnDefinition Width="*"></ColumnDefinition>
                        </Grid.ColumnDefinitions>
    <sdk:Label Content="Test" Grid.Row="2" Height="23" HorizontalAlignment="Left" Margin="4,2,0,0" Name="lbTest" VerticalAlignment="Top" Width="120" FontWeight="Bold" Grid.RowSpan="2" />
    </Grid>
    Monday, December 12, 2011 10:12 AM
  • Hi Syed,

    Thanks for your reply. I even tried with that without any success.

    Please tell anyother solution.

    Thanks

    Rahul

    Monday, December 12, 2011 11:27 AM
  • could you post the complete XAML of your control? The Grid should stretch fine.

    Monday, December 12, 2011 1:15 PM
  • Hi,

    please set the ShowGridLines="True"

    and you will find it runs ok.

     
    
    Wednesday, December 14, 2011 2:03 AM
  • Hi,

    Its still not working..

    Anyother solution.

    Please tell me.

    Thanks

    Rahul

    Wednesday, December 14, 2011 7:49 AM
  • Try This Resolution 1024*768Money mouth

    it s working

    Wednesday, December 14, 2011 9:33 AM
  • Hi,

    I want it to work in every resolution, i.e even if i change the resolution, it should work.

    Thanks

    Rahul

    Wednesday, December 14, 2011 11:42 AM
  • even if i change the resolution, it should work.

    Hi,

    do you mean you will change the display resolution when you are running the application?

    Wednesday, December 14, 2011 8:38 PM
  • As far as I know,If you change the display resolution,the silverlight plugin will not be notified. So you should try another way.

    you can get the resolution by javascript:

    var width = screen.width;
    var height = screen.height;

    Then you can call silverlight method by javascript to change the scale of your grid

    Wednesday, December 14, 2011 8:45 PM