Click here to Skip to main content
12,756,447 members (31,458 online)
Rate this:
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 1: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 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 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 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
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 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)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170217.1 | Last Updated 19 Dec 2012
Copyright © CodeProject, 1999-2017
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