Click here to Skip to main content
16,020,459 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
Hi,

I have a image slide containing 4 images in a page in windows phone. i have four buttons in other page. when i click on button1 image1 should be displayed . likely when i press button4 image4 should be displayed.....

can you please suggest me solving this...


Regards.
Posted

yes


(width of image1)+(left margin of image1)+(right margin of image1)+(left margin of image2)

another alternative could be
C#
int cnt=0;
foreach (Image img in ScrollViewerObj)
               {
if(cnt == buttonno)
break;

                   GeneralTransform gt = img.TransformToVisual(null);
                   Point p = gt.TransformPoint(new Point(0, 0));
}
ScrollViewerObj.HorizontalOffset(p.X);
 
Share this answer
 
v3
Comments
Raghavanand 14-Dec-12 6:01am    
lots of thanks !!!
Raghavanand 17-Dec-12 1:47am    
where should i define the above !! on button click or on page load
Naz_Firdouse 17-Dec-12 4:05am    
On page load, access the buttonno value and write the above code
Raghavanand 17-Dec-12 7:26am    
I am not getting this button no. and Point p.how to get that .can you show with a example if you dont mind !! I am completely new to windows mobile dev
Hi,
do u wanna display each image at a time r selected image should b highlighted along with others?
If ur requirement is second one, place all the images in a scrollviewer and set
ScrollviewerObj.HorizontalOffset(someval) which will shows your required image.

Here u need to find the "someval" value based on the button click like if u clicked on third button, you should get the widths of first two images and margin values(if any), sum up and send it as a parameter to ScrollviewerObj.HorizontalOffset(someval).
 
Share this answer
 
Comments
Raghavanand 14-Dec-12 5:41am    
Thanks a lot sir, I really mean it !!!
Raghavanand 14-Dec-12 5:45am    
But can u send it with a example how to set the parameter. i mean for image2 should i add width of image1 and margin of second image
Here is the sample code . Hope it helps.

In buttonPage.xaml,
HTML
<!--ContentPanel - place additional content here-->
      <grid x:name="ContentPanel" grid.row="1" margin="12,0,12,0" xmlns:x="#unknown">
          <stackpanel>
              <Button Content="Button1" Click="Button_Click"/>
              <Button Content="Button2" Click="Button_Click"/>
              <Button Content="Button3" Click="Button_Click"/>
              <Button Content="Button4" Click="Button_Click"/>
          </stackpanel>
      </grid>

In buttonPage.xaml.cs,
C#
private void Button_Click(object sender, RoutedEventArgs e)
       {
           string c=(sender as Button).Content.ToString().Substrin((sender  as Button).Content.ToString().Length-1);
           NavigationService.Navigate(new Uri("/ImagesPage.xaml?ImageNo="+c,UriKind.RelativeOrAbsolute));
       }


ImagePage.xaml,
C#
<!--ContentPanel - place additional content here-->
      <grid x:name="ContentPanel" grid.row="1" margin="0,0,0,0" xmlns:x="#unknown">
          <scrollviewer x:name="ImgScrollViewer" scrollviewer.horizontalscrollbarvisibility="Visible" verticalscrollbarvisibility="Auto">
              <stackpanel orientation="Horizontal" x:name="ImagesSP" scrollviewer.manipulationmode="Control" scrollviewer.horizontalscrollbarvisibility="Visible" scrollviewer.verticalscrollbarvisibility="Auto" loaded="ImagesSP_Loaded">
                  <!--<StackPanel.RenderTransform>
                      <TranslateTransform Y="550"/>
                  </StackPanel.RenderTransform>-->
                  <image source="Images\MediumGray.png" width="480" height="400" stretch="Fill" />
                  <image source="Images\msweb-brand.png" width="480" height="400" stretch="Fill" />
                  <image source="Images\videos.png" width="480" height="400" stretch="Fill" />
                  <image source="Images\MediumGray.png" width="480" height="400" stretch="Fill" />
              </stackpanel>
          </scrollviewer>
      </grid>


ImagePage.xaml.cs:
C#
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
       {

           NavigationContext.QueryString.TryGetValue("ImageNo", out imageNo);

       }

       private void ImagesSP_Loaded(object sender, RoutedEventArgs e)
       {
           double offset = 0;
           int cnt = 1;
           foreach (Image img in ImagesSP.Children)
           {
               cnt++;
               offset += img.Width;
               if (cnt == Convert.ToInt32(imageNo))
                   break;
           }

           ImgScrollViewer.ScrollToHorizontalOffset(offset);
       }
 
Share this answer
 
Comments
Raghavanand 19-Dec-12 8:14am    
Everything's working perfect sir !! but first image is not displaying !! showing invalid cast exception !!

But a lot of thanks sir!! Thanks for the answer
Naz_Firdouse 20-Dec-12 1:56am    
check whether you have an image with that name in Images folder

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