locked
Resizing screen RRS feed

  • Question

  • Hi,

    How to resize the screen of silverlight page

     

    Using CTR++ and CTR- - to resize the screen (like google.com)

     

    Thanks in Advance

     

    Tuesday, July 14, 2009 2:36 AM

Answers

  •  Hi,

    Very good question i m also working on that concept and finally i got it perfectly and the answer is:

    In xaml source if u want resize the screen as per resolution u must do all your work in Canvas and use all textbox and other in between Canvas and after that just Transform ur canvas like this: 
    XAML source & CS code 
    class="XYZ"
       xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    	xmlns:swc="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
    	Width="1024" Height="650" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows" xmlns:System_Windows_Controls_Primitives="clr-namespace:System.Windows.Controls.Primitives;assembly=System.Windows.Controls"
    	xmlns:slv="clr-namespace:Silverlight.Validators;assembly=Silverlight.Validators"
        xmlns:slvf="clr-namespace:Silverlight.Validators.Filters;assembly=Silverlight.Validators">
        <UserControl.Background>
            <LinearGradientBrush  EndPoint="0.5,1" StartPoint="0.5,0"&gt;
                <GradientStop Color="#FF000000"/>
                <GradientStop Color="#868650" Offset="1"/>
                <GradientStop Color="#c7ca9b" Offset="0.05299999937415123"/>
            </LinearGradientBrush>
        </UserControl.Background>
        <Grid x:Name="LayoutRoot" Background="#878751" Width="1024" Height="650"&gt;
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" MinHeight="650"/>
            </Grid.RowDefinitions>
            <Canvas x:Name="canvas" Margin="0,2.151,0,-0.151" RenderTransformOrigin="0,0" ToolTipService.ToolTip="" HorizontalAlignment="Left" Width="1021" VerticalAlignment="Stretch"&gt;
                <Canvas.Background>
                    <ImageBrush ImageSource="BackImg/LC_Clorophyl_1024x768ddd.png"/>
                </Canvas.Background>
                <Canvas.RenderTransform>
                    <ScaleTransform x:Name="CanvasScale" ScaleX="1" ScaleY="1"/>
                </Canvas.RenderTransform>
    
     <TextBlock Height="17.91" Width="123.679" Canvas.Left="539.65" Canvas.Top="40.09" Text="Father's Name" TextWrapping="Wrap" FontSize="16" Foreground="#FF000000"/>
                <TextBox Cursor="IBeam" x:Name="txtFather"   Height="25" Width="140" Canvas.Left="659" Canvas.Top="38.363" Text="" TextWrapping="Wrap" BorderBrush="#FF000000" FontSize="12"/>
    
    
                <TextBlock Height="17.27" Width="121.03" Canvas.Left="217" Canvas.Top="69.73" Text="Office Address" TextWrapping="Wrap" Foreground="#FF000000" FontSize="16"/>
                <TextBlock Height="21.135" Width="157.013" Text="Residense Address" TextWrapping="Wrap" HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Row="1" Canvas.Top="69.43" Canvas.Left="538.992" FontSize="16" Foreground="#FF000000" RenderTransformOrigin="0.5,0.5">
    
    
    
    
     
    Now XAML.CS code
    
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    using System.Collections;
    using System.Collections.ObjectModel;
    
    
    
    
    
    
    namespace fgh
    {
        public partial class hgfh : fghfgh
        {
    
           
            private int _startingWidth = 1024;/* starting width of resize page */
            private int _startingHeight = 650;/* startin height of resize page*/
        }
      public dfgfdg()
            {
                InitializeComponent();
                funContent_Resized();
                App.Current.Host.Content.Resized += new EventHandler(Content_Resized);
            }
           void Content_Resized(object sender, EventArgs e)
            {
                double height = App.Current.Host.Content.ActualHeight;
                double width = App.Current.Host.Content.ActualWidth;
                CanvasScale.ScaleX = width / _startingWidth;
                CanvasScale.ScaleY = height / _startingHeight;
            }
            
            void funContent_Resized()
            {
                double height = App.Current.Host.Content.ActualHeight;
                double width = App.Current.Host.Content.ActualWidth;
                CanvasScale.ScaleX = width / _startingWidth;
                CanvasScale.ScaleY = height / _startingHeight;
            }
    
    
    }
      Plz marked as answer if u got your soltution

     

    Regard

    Prateek
    Tuesday, July 14, 2009 8:11 AM

All replies

  •  Hi,

    Very good question i m also working on that concept and finally i got it perfectly and the answer is:

    In xaml source if u want resize the screen as per resolution u must do all your work in Canvas and use all textbox and other in between Canvas and after that just Transform ur canvas like this: 
    XAML source & CS code 
    class="XYZ"
       xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    	xmlns:swc="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
    	Width="1024" Height="650" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows" xmlns:System_Windows_Controls_Primitives="clr-namespace:System.Windows.Controls.Primitives;assembly=System.Windows.Controls"
    	xmlns:slv="clr-namespace:Silverlight.Validators;assembly=Silverlight.Validators"
        xmlns:slvf="clr-namespace:Silverlight.Validators.Filters;assembly=Silverlight.Validators"&gt;
        <UserControl.Background>
            <LinearGradientBrush  EndPoint="0.5,1" StartPoint="0.5,0"&gt;
                <GradientStop Color="#FF000000"/>
                <GradientStop Color="#868650" Offset="1"/>
                <GradientStop Color="#c7ca9b" Offset="0.05299999937415123"/>
            </LinearGradientBrush>
        </UserControl.Background>
        <Grid x:Name="LayoutRoot" Background="#878751" Width="1024" Height="650"&gt;
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" MinHeight="650"/>
            </Grid.RowDefinitions>
            <Canvas x:Name="canvas" Margin="0,2.151,0,-0.151" RenderTransformOrigin="0,0" ToolTipService.ToolTip="" HorizontalAlignment="Left" Width="1021" VerticalAlignment="Stretch"&gt;
                <Canvas.Background>
                    <ImageBrush ImageSource="BackImg/LC_Clorophyl_1024x768ddd.png"/>
                </Canvas.Background>
                <Canvas.RenderTransform>
                    <ScaleTransform x:Name="CanvasScale" ScaleX="1" ScaleY="1"/>
                </Canvas.RenderTransform>
    
     <TextBlock Height="17.91" Width="123.679" Canvas.Left="539.65" Canvas.Top="40.09" Text="Father's Name" TextWrapping="Wrap" FontSize="16" Foreground="#FF000000"/>
                <TextBox Cursor="IBeam" x:Name="txtFather"   Height="25" Width="140" Canvas.Left="659" Canvas.Top="38.363" Text="" TextWrapping="Wrap" BorderBrush="#FF000000" FontSize="12"/>
    
    
                <TextBlock Height="17.27" Width="121.03" Canvas.Left="217" Canvas.Top="69.73" Text="Office Address" TextWrapping="Wrap" Foreground="#FF000000" FontSize="16"/>
                <TextBlock Height="21.135" Width="157.013" Text="Residense Address" TextWrapping="Wrap" HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Row="1" Canvas.Top="69.43" Canvas.Left="538.992" FontSize="16" Foreground="#FF000000" RenderTransformOrigin="0.5,0.5">
    
    
    
    
     
    Now XAML.CS code
    
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    using System.Collections;
    using System.Collections.ObjectModel;
    
    
    
    
    
    
    namespace fgh
    {
        public partial class hgfh : fghfgh
        {
    
           
            private int _startingWidth = 1024;/* starting width of resize page */
            private int _startingHeight = 650;/* startin height of resize page*/
        }
      public dfgfdg()
            {
                InitializeComponent();
                funContent_Resized();
                App.Current.Host.Content.Resized += new EventHandler(Content_Resized);
            }
           void Content_Resized(object sender, EventArgs e)
            {
                double height = App.Current.Host.Content.ActualHeight;
                double width = App.Current.Host.Content.ActualWidth;
                CanvasScale.ScaleX = width / _startingWidth;
                CanvasScale.ScaleY = height / _startingHeight;
            }
            
            void funContent_Resized()
            {
                double height = App.Current.Host.Content.ActualHeight;
                double width = App.Current.Host.Content.ActualWidth;
                CanvasScale.ScaleX = width / _startingWidth;
                CanvasScale.ScaleY = height / _startingHeight;
            }
    
    
    }
      Plz marked as answer if u got your soltution

     

    Regard

    Prateek
    Tuesday, July 14, 2009 8:11 AM
  • this is not working when i change the system resolution.

    if i increase the system resolution i should not get the white space

    Tuesday, July 14, 2009 8:16 AM
  • Hi, its work perfect for me on my system so, pz send code

     

    Regard 

    Prateek

     

     

     

    Tuesday, July 14, 2009 8:22 AM