Click here to Skip to main content
11,806,378 members (64,917 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C# Mobile XAML Silverlight , +

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...

Posted 12-Dec-12 0:42am
Rate this: bad
Please Sign up or sign in to vote.

Solution 2


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

another alternative could be
int cnt=0;
foreach (Image img in ScrollViewerObj)
if(cnt == buttonno)
                   GeneralTransform gt = img.TransformToVisual(null);
                   Point p = gt.TransformPoint(new Point(0, 0));
Raghavanand at 14-Dec-12 6:01am
lots of thanks !!!
Raghavanand at 17-Dec-12 1:47am
where should i define the above !! on button click or on page load
Naz_Firdouse at 17-Dec-12 4:05am
On page load, access the buttonno value and write the above code
Raghavanand at 17-Dec-12 7:26am
I am not getting this button no. and Point to get that .can you show with a example if you dont mind !! I am completely new to windows mobile dev
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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).
Raghavanand at 14-Dec-12 5:41am
Thanks a lot sir, I really mean it !!!
Raghavanand at 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
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

Here is the sample code . Hope it helps.

In buttonPage.xaml,
<!--ContentPanel - place additional content here-->
      <grid x:name="ContentPanel" grid.row="1" margin="12,0,12,0" xmlns:x="#unknown">
              <Button Content="Button1" Click="Button_Click"/>
              <Button Content="Button2" Click="Button_Click"/>
              <Button Content="Button3" Click="Button_Click"/>
              <Button Content="Button4" Click="Button_Click"/>
In buttonPage.xaml.cs,
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));

<!--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">
                      <TranslateTransform Y="550"/>

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)
               offset += img.Width;
               if (cnt == Convert.ToInt32(imageNo))
Raghavanand at 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 at 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)

  Print Answers RSS
0 Richard Deeming 225
1 OriginalGriff 195
2 Sergey Alexandrovich Kryukov 170
3 ppolymorphe 125
4 Abhinav S 120
0 OriginalGriff 3,330
1 Maciej Los 1,990
2 KrunalRohit 1,907
3 CPallini 1,905
4 Richard MacCutchan 1,227

Advertise | Privacy | Mobile
Web01 | 2.8.151002.1 | Last Updated 19 Dec 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100