Navigation null geocoordinate - c#

I am totally beginner and I need some help, I am doing my application for Windows Phone 8 and I have problem with navigate to item, is like guide for example from shopping to show in item information and maps. I use web server to put all my data there and is connected with my application. Is looking for my actual position but is null with navigateitem and it can't go to another xaml because of it (itempage).
public ItemPage()
{
InitializeComponent();
this.DataContext = Globals.NavigationItem;
MapOverlay overlay = new MapOverlay();
overlay.Content = new Pushpin() { Background = new SolidColorBrush(Colors.Green) }; ;
overlay.GeoCoordinate = Globals.MyPosition;
MapOverlay itemoverlay = new MapOverlay();
itemoverlay.Content = new Pushpin() { Background = new SolidColorBrush(Colors.Blue) };
itemoverlay.GeoCoordinate = new GeoCoordinate(double.Parse(Globals.NavigationItem.Latitude), double.Parse(Globals.NavigationItem.Longitude));
MapLayer layer = new MapLayer();
layer.Add(overlay);
Mymap.Layers.Add(layer);
MapLayer itemlayer = new MapLayer();
itemlayer.Add(itemoverlay);
Mymap.Layers.Add(itemlayer);
Mymap.Center = new GeoCoordinate(double.Parse(Globals.NavigationItem.Latitude), double.Parse(Globals.NavigationItem.Longitude));
Mymap.ZoomLevel = 15;
}
The actual position is working well
private void GetUserLocation()
{
GeoCoordinateWatcher geo = new GeoCoordinateWatcher();
geo.PositionChanged += (x, y) =>
{
Globals.MyPosition = y.Position.Location;
};
geo.Start();
}
And this is navigate from shopping xaml to item xaml
private void Grid_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
Globals.NavigationItem = (sender as Grid).DataContext as Item;
NavigationService.Navigate(new Uri("/Views/ItemPage.xaml", UriKind.RelativeOrAbsolute));
}
I am sorry maybe question is stupid but liked I said in the beginning I am totally beginner, hope somebody can help me :)
=>
I was wondering maybe here is some mistake because the actual location is good, server is working because took the data and put
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
ServiceReference1.Service1Client client = new ServiceReference1.Service1Client();
client.GetZakupyAsync();
client.GetZakupyCompleted += (x, y) =>
{
if (Globals.MyPosition != null)
{
ZakupyBox.ItemsSource = y.Result.Where(p => Globals.MyPosition.GetDistanceTo(new GeoCoordinate(double.Parse(p.Latitude), double.Parse(p.Longitude))) < 5000);
if (ZakupyBox.Items.Count == 0)
{
ZakupyBox.ItemsSource = y.Result;
}
}
else
{
ZakupyBox.ItemsSource = y.Result;
}
};
}

Related

Virtual Listview with pictures : How to fill all the column space with the picture

I'm trying to setup a listview with pictures.
As i have 3000+ items in that list i'm using the VirtualMode.
Here is my code :
ImageList il = new ImageList();
private void artistList_Load(object sender, EventArgs e)
{
var art_list = from res in Globals.ds.Tables[0].AsEnumerable()
.GroupBy(x => x.Field<int>("Artist_ID"))
.Select(x => new { artiste = x.Select(p => p.Field<string>("artiste")).First(), fp = x.Select(p => p.Field<string>("file_path")).First() })
.OrderBy(x=>x.artiste)
select res.fp;
fp = art_list.ToList();
int buffer = 20;
il.ImageSize = new Size(90, 90);
listView1.VirtualMode = true;
for (int i = 0; i< buffer; i++)
{
il.Images.Add(i.ToString(), Globals.getMp3Image(fp[i]));
}
listView1.LargeImageList = il;
listView1.VirtualListSize = fp.Count();
}
private void listView1_RetrieveVirtualItem(object sender, RetrieveVirtualItemEventArgs e)
{
if (e.Item == null) e.Item = new ListViewItem(e.ItemIndex.ToString());
e.Item.ImageIndex = il.Images.IndexOfKey(e.ItemIndex.ToString());
}
I'm using a buffer of 20 and i'll try to implement a cache mechanism later.
My issue is the visual result i'm getting, here is a picture :
I have several issues here :
1/ the number below the picture should be the index, but why is it displayed ?
2/ i'd like to expand the picture to the to avoid the white spaces in the 4 directions (there is some white spaces in the left)
3/ i'd like to avoid the horizontal scrollbar (but i think this issue is linked to #2)
Here is the Designer info : (the view is set to LargeIcon)
this.listView1.Dock = System.Windows.Forms.DockStyle.Fill;
this.listView1.HideSelection = false;
this.listView1.Location = new System.Drawing.Point(0, 0);
this.listView1.Margin = new System.Windows.Forms.Padding(0);
this.listView1.Name = "listView1";
this.listView1.ShowGroups = false;
this.listView1.Size = new System.Drawing.Size(137, 657);
this.listView1.TabIndex = 0;
this.listView1.UseCompatibleStateImageBehavior = false;
this.listView1.RetrieveVirtualItem += new System.Windows.Forms.RetrieveVirtualItemEventHandler(this.listView1_RetrieveVirtualItem);
Of course i've tried to set the Size of the listview at 90 but it's worst.

Sliding panels - one works, the others don't

I've run into a bit of a wall and I don't know how I've managed to stuff it up. I'm trying to have multiple panels on my application in C# and each slides in and out from the menu along the side. I've written a separate slide class:
class Slide
{
Panel pane;
Button btn;
bool hidden;
Timer t;
const int maxWidth = 315;
public Slide(Panel p, Button b)
{
this.pane = p;
this.btn = b;
hidden = true;
btn.Click += new EventHandler(btnClick);
t = new Timer();
t.Interval = 15;
t.Tick += new EventHandler(timeTick);
}
private void timeTick(object sender, EventArgs e)
{
if(hidden)
{
SlidingPane(+10);
}
else
{
SlidingPane(-10);
}
}
private void btnClick(object sender, EventArgs e)
{
t.Start();
}
private void SlidingPane(int i)
{
pane.Width += i;
if(pane.Width >= maxWidth || pane.Width <= 0)
{
t.Stop();
hidden = !hidden;
}
}
}
And I've initialised the panels as follows:
Slide menuP, calendarP, peopleP, taskP, settingsP;
public Form1()
{
InitializeComponent();
ButtonColours();
InitialisePanes();
}
private void InitialisePanes()
{
menuP = new Slide(menuPane, menuButton);
calendarP = new Slide(calendarPane, calendarButton);
peopleP = new Slide(peoplePane, peopleButton);
taskP = new Slide(taskPane, toDoButton);
settingsP = new Slide(settingsPane, settingsButton);
}
And here's the Form designer code for the working panel:
this.menuPane.BackColor = System.Drawing.Color.SlateGray;
this.menuPane.Controls.Add(this.peoplePane);
this.menuPane.Dock = System.Windows.Forms.DockStyle.Left;
this.menuPane.Location = new System.Drawing.Point(67, 0);
this.menuPane.Name = "menuPane";
this.menuPane.Size = new System.Drawing.Size(0, 652);
this.menuPane.TabIndex = 2;
And the others are exactly the same. Eg:
this.peoplePane.BackColor = System.Drawing.Color.SlateGray;
this.peoplePane.Controls.Add(this.calendarPane);
this.peoplePane.Dock = System.Windows.Forms.DockStyle.Left;
this.peoplePane.Location = new System.Drawing.Point(67, 0);
this.peoplePane.Name = "peoplePane";
this.peoplePane.Size = new System.Drawing.Size(0, 652);
this.peoplePane.TabIndex = 2;
I've started up my application and I click on the menuButton, it works. Slides in and out beautifully. I click on the others and....nothing happens.
Can anyone see why this is happening? Everything I'm looking at tells me that it should be working.
To make sure all panes are correctly aligned with each other and (not) nested you could use code like this:
foreach( Control ctl in new[] { peoplePane, calendarPane, taskPane, settingsPane })
{
ctl.Parent = menuPane.Parent;
ctl.Location = menuPane.Location;
}
It assumes that menuPane is at the right spot and makes all others sit right on top without nesting them.
The code you posted contained incorrect nesting and moving panels to the same spot with the mouse will also create (in this case unwanted) nesting. Moving with the keyboard avoids it but is tedious.

How to create draggable pin in windows 10 to give pick location functionality?

I am working on MapControl in Windows 10 and I want to allow the user to drag the pin and when the user drops the pin want to get latitude and longitude of that position and get the location address by using API.I added Map Icon using following code
MapControl map = frameworkElement as MapControl;
map.MapServiceToken= "my service token";
BasicGeoposition councilPosition = new BasicGeoposition()
{
Latitude = Convert.ToDouble(Info.GetType().GetRuntimeProperty("LATITUDE").GetValue(councilInfo, null)),
Longitude = Convert.ToDouble(Info.GetType().GetRuntimeProperty("LONGITUDE").GetValue(councilInfo, null))
};
Geopoint pinPoint = new Geopoint(councilPosition);
MapIcon locationPin = new MapIcon();
locationPin.Image= RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Images/pushpin.png"));
locationPin.Title = councilInfo.COUNCIL_NAME;
locationPin.CollisionBehaviorDesired = MapElementCollisionBehavior.RemainVisible;
locationPin.Location = councilPoint;
locationPin.NormalizedAnchorPoint = new Point(0.5, 1.0);
locationPin.ZIndex = 0;
map.MapElements.Add(locationPin);
await map.TrySetViewAsync(locationPin.Location, 15D, 0, 0, MapAnimationKind.Bow);
Can someone suggest which events are required to be used to achieve pick location functionality?
Refer this link. They have specified display points using XAML. Instead of border you can have Grid with background pushpin image,listen to manipulation events for that grid.
here is the code to achieve what i told above.
private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
BasicGeoposition snPosition = new BasicGeoposition() { Latitude = 47.7356039173901, Longitude = -122.310697222129
};
Geopoint snPoint = new Geopoint(snPosition);
// Create a XAML border.
Grid grid = new Grid
{
Width=100,
Height=100,
Background = new ImageBrush() {ImageSource= new BitmapImage(new Uri("ms-appx:///Assets/icon.png", UriKind.RelativeOrAbsolute)), Stretch = Stretch.UniformToFill}
};
grid.ManipulationMode = ManipulationModes.TranslateX|ManipulationModes.TranslateY;
grid.ManipulationCompleted += Grid_ManipulationCompleted;
grid.ManipulationDelta +=Grid_ManipulationDelta;
// Center the map over the POI.
MapControl1.Center = snPoint;
MapControl1.ZoomLevel = 14;
CompositeTransform tran = new CompositeTransform();
grid.RenderTransform = tran;
// Add XAML to the map.
MapControl1.Children.Add(grid);
MapControl.SetLocation(grid, snPoint);
MapControl.SetNormalizedAnchorPoint(grid, new Point(0.5, 0.5));
}
private void Grid_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
{
Grid grid = sender as Grid;
CompositeTransform xform = grid.RenderTransform as CompositeTransform;
xform.TranslateX += e.Delta.Translation.X;
xform.TranslateY += e.Delta.Translation.Y;
// Rect point = grid.TransformToVisual(MapControl1).TransformBounds(new Rect(0,0, grid.Width, grid.Height));
e.Handled = true;
// Geopoint gPoint;
// MapControl1.GetLocationFromOffset(new Point(point.X, point.Y), out gPoint);
// Debug.WriteLine(gPoint.Position.Latitude);
// Debug.WriteLine(gPoint.Position.Longitude);
}
private void Grid_ManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e)
{
Grid grid = sender as Grid;
Rect point = grid.TransformToVisual(MapControl1).TransformBounds(new Rect(0, 0, grid.Width, grid.Height);
Geopoint gPoint;
MapControl1.GetLocationFromOffset(new Point(point.X, point.Y), out gPoint);
Debug.WriteLine(gPoint.Position.Latitude);
Debug.WriteLine(gPoint.Position.Longitude);
}
Location fetched after drag is not that accurate. You can do bit R&D on how to fetch accuarate point wrt to MapControl
I was unable to get the accepted answer to work. After a lot of research and help from this answer, I finally got it working. Here's a working sample:
public sealed partial class MainPage : Page
{
public MainPage()
{
InitializeComponent();
var position = new Geopoint(new BasicGeoposition
{
Latitude = 30.3618,
Longitude = -91.1067
});
var grid = new Grid
{
Width = 32,
Height = 50
};
var pushpin = new Image()
{
Source = new BitmapImage(new Uri("ms-appx:///Assets/Pushpin.png")),
Stretch = Stretch.Uniform,
ManipulationMode = ManipulationModes.TranslateX | ManipulationModes.TranslateY,
RenderTransform = new TranslateTransform()
};
pushpin.ManipulationStarted += Pushpin_ManipulationStarted;
pushpin.ManipulationDelta += Pushpin_ManipulationDelta;
pushpin.ManipulationCompleted += Pushpin_ManipulationCompleted;
grid.Children.Add(pushpin);
Map.Center = position;
Map.Children.Add(grid);
MapControl.SetLocation(grid, position);
MapControl.SetNormalizedAnchorPoint(grid, new Point(0.5, 1));
}
private Geopoint GetPosition(Image pushpin)
{
var grid = pushpin.Parent as Grid;
var anchor = MapControl.GetNormalizedAnchorPoint(grid);
var offset = pushpin.TransformToVisual(Map).TransformPoint(new Point(grid.Width * anchor.X, grid.Height * anchor.Y));
Map.GetLocationFromOffset(offset, out Geopoint position);
return position;
}
private void Pushpin_ManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e)
{
Map.PanInteractionMode = MapPanInteractionMode.Auto;
var pushpin = sender as Image;
var grid = pushpin.Parent as Grid;
var position = GetPosition(pushpin);
MapControl.SetLocation(grid, position);
var transform = pushpin.RenderTransform as TranslateTransform;
transform.X = 0;
transform.Y = 0;
}
private void Pushpin_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
{
var pushpin = sender as Image;
var transform = pushpin.RenderTransform as TranslateTransform;
transform.X += e.Delta.Translation.X;
transform.Y += e.Delta.Translation.Y;
}
private void Pushpin_ManipulationStarted(object sender, ManipulationStartedRoutedEventArgs e)
{
Map.PanInteractionMode = MapPanInteractionMode.Disabled;
}
}

Bing Maps foreach item in list add new pushpin

I'm trying to add multiple pushpins from a list to Bing Maps on Windows Phone. The name of each pushpin needs to be different, because I want to be able to remove them individually later using MainMap.Children.Remove(SpecificPushpin);.
This is my foreach:
Pushpin pushpin = new Pushpin();
Attractions attractions = new Attractions();
foreach (var attraction in Attractions.allAttractions)
{
pushpin.GeoCoordinate = new GeoCoordinate(attraction.Latitude, attraction.Longtitude);
pushpin.Content = attraction.Title;
pushpin.Background = new SolidColorBrush(Colors.Blue);
pushpin.Foreground = new SolidColorBrush(Colors.White);
MainMap.Children.Add(pushpin);
}
Of course, I receive an error after the first loop through the foreach on the MainMap.Children.Add(pushpin); line, because "pushpin" is already an existing name.
I also tried using this:
MainMap.Children.Add(new Pushpin() { Content = attraction.Title, GeoCoordinate = new GeoCoordinate(attraction.Latitude, attraction.Longtitude), Background = new SolidColorBrush(Colors.Yellow), Foreground = new SolidColorBrush(Colors.Black) });
But then I will never be able to romove the pushpins individualy.
Does anyone know how I can give a variable name to each pushpin in my list, or knows another way to fix my problem?
Instead of using Bing Maps, I used the Map Control and worked with MapLayers and MapOverlay. I created a different MapLayer for each list class and removed those individually.
This made it possible to remove one list of pushpins simply. Here's an example:
private void LoadAttractions()
{
if (cbxAttractions.IsChecked != false)
{
Attractions attractions = new Attractions();
foreach (var attraction in Attractions.allAttractions)
{
Pushpin pushpin = new Pushpin();
pushpin.Name = attraction.Title;
pushpin.GeoCoordinate = new GeoCoordinate(attraction.Latitude, attraction.Longtitude);
pushpin.Content = attraction.Title;
pushpin.Background = new SolidColorBrush(Colors.Yellow);
pushpin.Foreground = new SolidColorBrush(Colors.Black);
MapOverlay MyOverlay = new MapOverlay();
mapLayerAttractions.Add(MyOverlay);
MyOverlay.Content = pushpin;
MyOverlay.GeoCoordinate = new GeoCoordinate(attraction.Latitude, attraction.Longtitude);
MyOverlay.PositionOrigin = new Point(0.0, 1.0);
}
MainMap.Layers.Add(mapLayerAttractions);
}
}
And when cbxAttractions is being tapped:
private void cbxAttractions_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
if (cbxAttractions.IsChecked == false)
{
MainMap.Layers.Remove(mapLayerAttractions);
}
else
{
LoadAttractions();
}
}
You can give each your Pushpin a property, for example:Tag. And Each tag is not same to another. So when you remove a specific pushpin. You can use foreach like this:
foreach(PushPin pushpin in yourPushpinList)
{
if (pushpin.Tag == yourValue)
{
MainMap.Children.Remove(SpecificPushpin);
break;
}
}
the code maybe not correct, it is just a example.

Trouble with sounds in xna

I have two main pages, GamePage (where all the code to play the game is in), and Mainpage (which is the title screen). What I want to be able to do is play music on the title screen (mainpage.xaml)
I have tried using the content.load method like I have done in the gamepage.xaml. But that does not work, it comes up with a null exception. I have also tried putting it in the section you can see in the screenshot entitled MazeEscapePhoneSilveright, but when i try to run it; the error unexpected characters in the sound file comes up.
How can I play music on the mainpage.xaml, nothing I've tried seems to:
Codebehind mainpage.xaml:
public partial class MainPage : PhoneApplicationPage
{
// Constructor
ContentManager contentManager;
MediaElement player = null;
Popup nameEntry = new Popup();
bool gameMusic;
bool mazeStart = true;
TextBox txtNameEntry = new TextBox();
SoundEffect theme_music;
SoundEffectInstance theme_music_Instance;
SoundEffect zap;
SoundEffectInstance zapInstance;
public MainPage()
{
InitializeComponent();
//SharedGraphicsDeviceManager.Current.GraphicsDevice.SetSharingMode(true);
//Plays the music through a mediaplayer, and a public boolean value.
if (App.Current.Resources.Contains("mediaPlayer"))
{
player = App.Current.Resources["mediaPlayer"] as MediaElement;
player.Source = new Uri("./MazeEscapePhoneSilverightLibContent/Media/magic_wav_file", UriKind.Relative);
}
gameMusic = ((App)Application.Current).gameMusic;
if (gameMusic) player.Play();
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
if (((App)Application.Current).gameMusic)
{
//theme_music = this.contentManager.Load<SoundEffect>("Media/magic_wav_file");
//theme_music_Instance = theme_music.CreateInstance();
}
}
//method runs when "Start Game" button is pressed
private void btnStartGame_Click(object sender, RoutedEventArgs e)
{
if (gameMusic)
{
player.Play();
}
#region CREATE AND DISPLAY POP UP
Border border = new Border();
border.BorderBrush = new SolidColorBrush(Colors.White);
border.BorderThickness = new Thickness(10);
StackPanel myStackPanel = new StackPanel();
myStackPanel.Background = new SolidColorBrush(Colors.Black);
//Textblock containing the name you input and its properties.
//txtNameEntry.Text = Microsoft.Phone.Info.DeviceExtendedProperties.GetValue("DeviceName").ToString();
txtNameEntry.Text = "Player 1";
txtNameEntry.Width = 350;
txtNameEntry.Height = 100;
txtNameEntry.MaxLength = 10;
txtNameEntry.FontFamily = new FontFamily("Comis Sans MS");
txtNameEntry.FontSize = 48.0;
txtNameEntry.Foreground = new SolidColorBrush(Colors.Orange);
txtNameEntry.Background = new SolidColorBrush(Colors.LightGray);
txtNameEntry.BorderBrush = new SolidColorBrush(Colors.LightGray);
//The ok button, which then allows you to procede into the game.
Button btnNameEntryOK = new Button();
btnNameEntryOK.Content = "Ok";
btnNameEntryOK.Background = new SolidColorBrush(Colors.Orange);
btnNameEntryOK.FontFamily = new FontFamily("Comic Sans Ms");
btnNameEntryOK.FontSize = 25.0;
btnNameEntryOK.Width = 180;
btnNameEntryOK.Height = 70;
btnNameEntryOK.Click += new RoutedEventHandler(btnNameEntryOK_Click);
btnNameEntryOK.Margin = new Thickness(10);
//Place these in the order you want them to be renderd to the screen.
myStackPanel.Children.Add(txtNameEntry);
myStackPanel.Children.Add(btnNameEntryOK);
border.Child = myStackPanel;
nameEntry.Child = border;
//set screen position of pop up
nameEntry.VerticalOffset = 100.0;
nameEntry.HorizontalOffset = 50.0;
//open pop up
nameEntry.IsOpen = true;
#endregion
if (nameEntry.IsOpen == false && mazeStart == true)
{
player.Stop();
}
}
void btnNameEntryOK_Click(object sender, RoutedEventArgs e)
{
((App)Application.Current).playerName = txtNameEntry.Text;
nameEntry.IsOpen = false;
mazeStart = true;
player.Stop();
NavigationService.Navigate(new Uri("/GamePage.xaml", UriKind.Relative));
}
private void btnOptions_Click(object sender, RoutedEventArgs e)
{
nameEntry.IsOpen = false;
NavigationService.Navigate(new Uri("/Options.xaml", UriKind.Relative));
}
Screenshot of the solution explorer:

Categories