Passing values between 2 pages in Wp7 havig scrollviewer - windows-phone-7

I have 2 pages in my app each page has one scrollviewer having image as an item added dynamically form URL. The first contain the first image.When I scroll to the end of first page the second page have to appear with the next image, viceversa when I scroll to the end of the second page now the first page should contain the third image and next the second with the 4th image. how to do that. It is like an ebook application.
This is in firstpage.xaml.cs
Image img = new Image();
Uri uri = new Uri("http://d1mu9ule1cy7bp.cloudfront.net/2012/media/catalogues/47/pages/p_" + i + "/high.jpg");
ImageSource img1 = new BitmapImage(uri);
img.Source = img1;
img.Height = 550;
Scrollview.Content = img;
private void Scrollview_MouseEnter(object sender, MouseEventArgs e)
{
this.NavigationService.Navigate(new Uri("/Page2.xaml", UriKind.Relative));
}
This is in secondpage.xaml.cs
int h = loop(j);
Image img = new Image();
Uri uri = new Uri("http://d1mu9ule1cy7bp.cloudfront.net/2012/media/catalogues/47/pages/p_" + h + "/high.jpg");
ImageSource img1 = new BitmapImage(uri);
img.Source = img1;
img.Height = 550;
Scrollview.Content = img;
private void Scrollview_MouseEnter(object sender, MouseEventArgs e)
{
this.NavigationService.Navigate(new Uri("/Page1.xaml", UriKind.Relative));
}

I would consider using a ListBox instead. It is a very powerful control.

I would recommend you to detect the end of scroll position on the first page and add the second image dynamically to that scollviewer itself. Something like infinite scrolling, similar to that of news feed in facebook app for wp7.

Related

Label is not show in print

I have used below code to print the Panel of windows form.
private void button1_Click(object sender, EventArgs e)
{
System.Drawing.Printing.PrintDocument doc = new System.Drawing.Printing.PrintDocument();
doc.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(Doc_PrintPage);
doc.Print();
}
private void Doc_PrintPage(object sender, PrintPageEventArgs e)
{
Panel grd = new Panel();
Bitmap bmp = new Bitmap(panel2.Width, panel2.Height, panel2.CreateGraphics());
panel2.DrawToBitmap(bmp, new Rectangle(0, 0, panel2.Width, panel2.Height));
RectangleF bounds = e.PageSettings.PrintableArea;
float factor = ((float)bmp.Height / (float)bmp.Width);
e.Graphics.DrawImage(bmp, bounds.Left, bounds.Top, bounds.Width, factor * bounds.Width);
bmp.Save("test12.jpg");
}
Now from above code, when i click on button the print function will be call but it excluded label in it. i am attaching image for your reference. first image is my UI design. , when i use print functionality it removes the label value as you can see in other image. i have used rectagleshap control which are in Pink color and i am displaying label on it. I think the label may be send back but when i used front back then also it is not appear.
Can you just try this one here i was using this for capture the whole screen which ever is active window its like screencapture or screenshot.
private void Doc_PrintPage(object sender, PrintPageEventArgs e)
{
Bitmap bitmap = new Bitmap(panel2.Width, panel2.Height);
Graphics graphics = Graphics.FromImage(bitmap as Image);
graphics.InterpolationMode = InterpolationMode.Default;
graphics.CopyFromScreen(0, 0, 0, 0, bitmap.Size);
bitmap.Save(pathDownload + filename + ".jpeg", ImageFormat.Jpeg);
bmp.Save("test12.jpg");
}
In my case label was shown back to the rectangle, so i added one more label and set it as bring front. thanks for the help.

Change page in pdfbox with Button

I'm working in JavaFX with PDFbox and I have this problem. I want to scroll Scroll through the pages of a pdf by clicking a button(when I press it I want to go to the next page). When I open the pdf then I show the first page with this code:
BufferedImage bi = new BufferedImage (500,500,BufferedImage.TYPE_INT_RGB);
Image img = SwingFXUtils.toFXImage(bi, null);
BufferedImage firstpage = new BufferedImage (500,500,BufferedImage.TYPE_INT_RGB);
firstpage = pdPages.get(0).convertToImage(BufferedImage.TYPE_INT_RGB, 100);
Image primapagina = SwingFXUtils.toFXImage(firstpage, null);
ImageView v ;
v = new ImageView(primapagina);
Then I created a button like this:
Button avanti = new Button(">>");
avanti.setStyle("-fx-font: 22 arial;");
Finally I created the handler,
avanti.setOnAction(new EventHandler<ActionEvent>() {
#Override public void handle(ActionEvent e) {
// final int j = i;
BufferedImage Xpage = null;
try {
Xpage = pdPages.get(8).convertToImage(BufferedImage.TYPE_INT_RGB, 100);
// System.out.printf("\n firstpage %d",t );
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
Image Xpagina = SwingFXUtils.toFXImage(Xpage, null);
v.setImage(Xpagina);
}
});
At the moment I put 8 just to see if it was working, and it was. But How can I ,by clicking the button, go to the next page? I thought about pointers, but I don't think it exist in JavaFX.
Thanks

How to give image to a pushpin dynamically in c#

I have a scenario where I would like the user to view multiple pushpins in Bing maps in a wp7 app. I used maplayer to make the cluster of pushpins, but I could not add an image to that pushpin dynamically in the cs file itself. By the way, I have not used the pushpin control in xaml. I'm just adding the pushpin object to the maplayer while looping through.
Here is my code:
maplayer layer = new maplayer();
watcher.start();
for (int i = 0; i < lst.count; i++)
{
Pushpin mypin = new Pushpin();
watcher.Position.Location.Latitude = Convert.ToDouble(lst[i].Latitude);
watcher.Position.Location.Longitude=Convert.ToDouble(lst[i].Longitude);
}
GeoCoordinate geo = new GeoCoordinate(watcher.Position.Location.Latitude, watcher.Position.Location.Longitude);
mypin.Location = geo;
mypin.Background = new SolidColorBrush(Colors.Gray);
mypin.Foreground = new SolidColorBrush(Colors.White);
mypin.Content = "My location";
layer.AddChild(mypin, mypin.Location);
}
map1.SetView(watcher.Position.Location, Status == true ? 5.0 : 3.0);
map1.Children.Add(layer);
watcher.stop();
I have also tried using the image brush property to provide image source to pushpin but the pushpin itself goes invisible.
like this:
ImageBrush ib = new ImageBrush();
ib.ImageSource = new System.Windows.Media.Imaging.BitmapImage(new Uri(#"Images/push.png", UriKind.Relative));
mypin.Background = ib;
Please help me on this. I need this to be done without changing/adding datatemplate to pushpin from the xaml side.
This problem is covered in MSDN, on the page for Working With Pushpins. Here is the example given, where images are added directly to a layer on the map:
namespace WindowsPhoneApplication1
{
public partial class MainPage : PhoneApplicationPage
{
MapLayer imageLayer;
public MainPage()
{
InitializeComponent();
//Create a layer to contain the pushpin images.
imageLayer = new MapLayer();
map1.Children.Add(imageLayer);
}
private GeoCoordinate mapCenter;
private void button1_Click(object sender, RoutedEventArgs e)
{
// Retrieve the center of the current map view.
mapCenter = map1.Center;
// Define the image to use as the pushpin icon.
Image pinImage = new Image();
//Define the URI location of the image.
pinImage.Source = new System.Windows.Media.Imaging.BitmapImage(new Uri("bluepushpin.png", UriKind.Relative));
//Define the image display properties.
pinImage.Opacity = 0.8;
pinImage.Stretch = System.Windows.Media.Stretch.None;
// Put the image at the center of the view.
PositionOrigin position = PositionOrigin.Center;
imageLayer.AddChild(pinImage, mapCenter, position);
}
}
}

How to refresh images in every second in windows 7 phone

i am showing images from server. In server image is changing in every second. I want that in my application image should be change automatically after one second.M new in windows 7 programming. Kindly suggest me where i am lacking in concept. M using this code.
This process will start when i will tab on my image.
private void image1_Tap(object sender, GestureEventArgs e)
{
System.Windows.Threading.DispatcherTimer dt = new System.Windows.Threading.DispatcherTimer();
dt.Interval = new TimeSpan(0, 0, 0, 0, 1000); // 500 Milliseconds
dt.Tick += new EventHandler(dt_Tick);
dt.Start();
}
This is calling this method .
void dt_Tick(object sender, EventArgs e)
{
status.Text = "chking" + counter++;
// Do Stuff here.
image1.Source = null;
Uri imgUri = new Uri(base_url,UriKind.Absolute);
BitmapImage BI = new BitmapImage(imgUri);
int H = BI.PixelHeight;
int w = BI.PixelWidth;
image1.Source = BI;
}
In this code my Counter is working fine and status.Text is sucessfully change in every second. But image is changing once after that its not changing.
Kinldy suggest me where i am commiting mistake.
Thanks in advance
Gaurav Gupta
I think you should declare System.Windows.Threading.DispatcherTimer dt = new System.Windows.Threading.DispatcherTimer(); as a member variable instead of declaring it in the images tap event.
I do the same thing when grabbing images from a camera in my wp8 app. I hold the URL including the current datetime-value as a url-param in my viewmodel. When i want to refresh, i just reset my URL-property.
Here's my sample:
this.MyUrlProperty = string.Format("{0}?timestamp={1:yyyy-MM-dd HH:mm:ss:fff}", _originalCameraUrl, DateTime.Now);
Works great for me...

make slide show wp7

I have to do a slide show off images stored in my isolated storage.. but i am beginner in windows phone and i have some dificulties.. i already know how to present the images, or show the images in the screen.. but i want to present the images 2 seconds each one.. theres some funcionalty to define the time to reproduce? Any example?
IsolatedStorageFileStream stream = new IsolatedStorageFileStream(name_image, FileMode.Open, myIsolatedStorage);
var image = new BitmapImage();
image.SetSource(stream);
image1.Source = image;
This is how i open the image. I have a foreach with 5 name of images then i open each one.. but i want to see the images 2 seconds..
You could make the current thread sleep for 2 seconds:
System.Threading.Thread.Sleep(2000);
As the last sentence in the foreach body. It is not very neat, but it will do the job.
A better way is to use Reactive Extension.
First take a look at my answer in this post. It tells you what dlls you will need as well as some useful links.
Basically you need to store you images in a collection and then use Rx (GenerateWithTime) to create a observable sequence with time dimension based on the collection. Finally you call a method to add one image and subscribe it to the observable sequence.
Here is one working example,
private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
// create a collection to store your 5 images
var images = new List<Image>
{
new Image() { Source = new BitmapImage(new Uri("/ApplicationIcon.png", UriKind.Relative)), Width = 120, Height = 120 },
new Image() { Source = new BitmapImage(new Uri("/ApplicationIcon.png", UriKind.Relative)), Width = 120, Height = 120 },
new Image() { Source = new BitmapImage(new Uri("/ApplicationIcon.png", UriKind.Relative)), Width = 120, Height = 120 },
new Image() { Source = new BitmapImage(new Uri("/ApplicationIcon.png", UriKind.Relative)), Width = 120, Height = 120 },
new Image() { Source = new BitmapImage(new Uri("/ApplicationIcon.png", UriKind.Relative)), Width = 120, Height = 120 }
};
// create a time dimension (2 seconds) to the generated sequence
IObservable<Image> getImages = Observable.GenerateWithTime(0, i => i <= images.Count - 1, i => images[i], _ => TimeSpan.FromSeconds(2), i => ++i);
// subscribe the DisplayOneImage handler to the sequence
getImages.ObserveOnDispatcher().Subscribe(DisplayOneImage);
}
private void DisplayOneImage(Image image)
{
// MyItems is an ItemsControl on the UI
this.MyItems.Items.Add(image);
}
Hope this helps. :)

Resources