Click here to Skip to main content
15,906,210 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I have two xaml pages . page1 having 10 buttons and page two having 10 images placed in horizontal scrollviewer.when i click on button it should scroll to that image. I am posting my code here.

MainPage.xaml

XML
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
           <ScrollViewer VerticalScrollBarVisibility="Auto">
               <toolkit:WrapPanel>

                   <Button BorderBrush="{x:Null}" Click="Button_Click" Name="button1">
                       <StackPanel>
                           <Image Name="image1" Source="/PhoneApp3;component/rhymes/10inabed.png" Stretch="Fill" Height="100" Width="150" />
                       </StackPanel>
                   </Button>
                   <Button Width="210" BorderBrush="{x:Null}" Click="Button_Click_1" Name="button2">
                       <StackPanel>
                           <Image Name="image2"  Source="/PhoneApp3;component/rhymes/abcsong.png" Margin="10" Height="100" Width="156"  />
                       </StackPanel>
                   </Button >
                   <Button BorderBrush="{x:Null}" Click="Button_Click_2" Name="button3">
                       <StackPanel>
                           <Image Name="image3" Source="/PhoneApp3;component/rhymes/baabaablacksheep.png" Stretch="Fill" Height="100" Width="150" />
                       </StackPanel>
                   </Button>
                   <Button Width="210" BorderBrush="{x:Null}" Click="Button_Click_3" Name="button4">
                       <StackPanel>
                           <Image Name="image4" Source="/PhoneApp3;component/rhymes/chubbycheeks.png" Margin="10" Height="100" Width="156"  />
                       </StackPanel>
                   </Button>
                   <Button BorderBrush="{x:Null}" Click="Button_Click_4" Name="button5">
                       <StackPanel>
                           <Image Name="image5" Source="/PhoneApp3;component/rhymes/daysoftheweek.png" Stretch="Fill" Height="100" Width="150" />
                       </StackPanel>
                   </Button>
                   <Button Width="210" BorderBrush="{x:Null}" Click="Button_Click_5" Name="button6">
                       <StackPanel>
                           <Image Name="image6" Source="/PhoneApp3;component/rhymes/fruittrain.png" Margin="10" Height="100" Width="156"  />
                       </StackPanel>
                   </Button>
                   <Button BorderBrush="{x:Null}" Click="Button_Click_6" Name="button7">
                       <StackPanel>
                           <Image Name="image7" Source="/PhoneApp3;component/rhymes/happybirthday.png" Stretch="Fill" Height="100" Width="150" />
                       </StackPanel>
                   </Button>
                   <Button Width="210" BorderBrush="{x:Null}" Click="Button_Click_7" Name="button8">
                       <StackPanel>
                           <Image Name="image8" Source="/PhoneApp3;component/rhymes/hickorydickory.png" Margin="10" Height="100" Width="156"  />
                       </StackPanel>
                   </Button>
                   <Button BorderBrush="{x:Null}" Click="Button_Click_8" Name="button9">
                       <StackPanel>
                           <Image Name="image9" Source="/PhoneApp3;component/rhymes/HumptyDumpty.png" Stretch="Fill" Height="100" Width="150" />
                       </StackPanel>
                   </Button>
                   <Button Width="210" BorderBrush="{x:Null}" Click="Button_Click_9" Name="button10">
                       <StackPanel>
                           <Image Name="image10" Source="/PhoneApp3;component/rhymes/incywincyspider.png" Margin="10" Height="100" Width="156"  />
                       </StackPanel>
</toolkit:WrapPanel>

            </ScrollViewer>

        </Grid>



page1.xaml

XML
<StackPanel Margin="12,0,12,0">
       <ScrollViewer VerticalScrollBarVisibility ="Disabled" HorizontalScrollBarVisibility="Hidden" x:Name="PageScrollViews">
           <ScrollViewer.Background>
               <ImageBrush ImageSource="/PhoneApp3;component/images/bg.png" />
           </ScrollViewer.Background>
           <Grid Margin="0,300,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" x:Name="Grid1">

               <Image Name="image1" Source="/PhoneApp3;component/images/10InABedImg.png" Height="500" Width="480" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="0,0,480,102"  />
               <Image Name="image2" Source="/PhoneApp3;component/rhymes/abcsong.png" Height="500" Width="480" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="480,0,0,102" Tag="2" />
               <Image Name="image3" Source="/PhoneApp3;component/rhymes/baabaablacksheep.png" Height="500" Width="480" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="960,0,0,102"/>
               <Image Name="image4" Source="/PhoneApp3;component/rhymes/chubbycheeks.png" Height="500" Width="480" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="1440,0,0,102"/>
               <Image Name="image5" Source="/PhoneApp3;component/rhymes/daysoftheweek.png" Height="500" Width="480" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="1920,0,0,102"/>
               <Image Name="image6" Source="/PhoneApp3;component/rhymes/fruittrain.png" Height="500" Width="480" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="2400,0,0,102"/>
               <Image Name="image7" Source="/PhoneApp3;component/rhymes/happybirthday.png" Height="500" Width="480" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="2880,0,0,102"/>
               <Image Name="image8" Source="/PhoneApp3;component/rhymes/hickorydickory.png" Height="500" Width="480" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="3360,0,0,102"/>
               <Image Name="image9" Source="/PhoneApp3;component/rhymes/HumptyDumpty.png" Height="500" Width="480" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="3840,0,0,102"/>
               <Image Name="image10" Source="/PhoneApp3;component/rhymes/incywincyspider.png" Height="500" Width="480" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="4320,0,0,102"/>

HTML
</Grid>
        </ScrollViewer>
    </StackPanel>


how to scroll to particular image on button click from previous page
Posted

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900