I am a newbie
I have a database with addresses and longitude/ lattitude data.
I want to write a small windows application that is able to put multiple pushpins or other marks on the map using longitude and lattitude-
The user types ind the address
The system gets the longitude and laittude and adds the pushpins on the map.
I really need some help and guidance to get started.
I can manage th database call and gui stuff, but i havent been able to successfully adding a bing map and set the pushpins in a simple winform application yet.
Im using visual studio 2012
I have downloaded and installed the Bing Maps WPF control
So adding a map to a wpf app is super easy. Following the steps here: https://msdn.microsoft.com/en-us/library/hh745791.aspx
I'll quickly go over the steps mentioned in the article:
Step 1. You have already completed since you have the Bing Maps WPF control.
Step 2. Get a Bing Maps Key
Step 3. Add the xmlns:m annotation to your Window
xmlns:m="clr-namespace:Microsoft.Maps.MapControl.WPF;assembly=Microsoft.Maps.MapControl.WPF"
Step 4. Add a maps Control to your Window. It will be nested within something like the
Like this
<Grid>
<m:Map x:Name="myMap"
CredentialsProvider="Your Key From Step 2"/>
</Grid>
Step 5. In your Code behind, add pins to your map
public MainWindow()
{
InitializeComponent();
Pushpin pin = new Pushpin();
pin.Location = new Location(37.1481402218342, -119.644248783588);
// Adds the pushpin to the map.
myMap.Children.Add(pin);
// Removes pushpin from the map.
// myMap.Children.Remove(pin);
}
Related
I've created line series chart application for windows phone 8.1.
Code is here-
<Charting:LineSeries Title="Rating" Margin="0" IndependentValuePath="Name" DependentValuePath="Amount" IsSelectionEnabled="True" >
</Charting:LineSeries >
Here is Output -
In desktop application(wpf) datapoint detail shown while mousehover on them but In windows phone there is no event like desktop(wpf)
I want to get datapoint details while clicking on them.
How can I get this on data point click?
You will need to copy your mouseover events to Tapped events. Inside Tapped events you can write do a check by encasing code in #if WINDOWS_PHONE_APP block if you want it to work only for Phone.
There is also an option of defining <ToolTipService.ToolTip > template inside your control but as per user experience it wont give satisfactory result.
How can I get the default back button on an iOS UINavigationController? I have the button being added in code, but I want the default style. Is there an Enum of System Images that contains the '<', or is there not really a way, and Ill have to design my own?
Heres the code to make the button:
controller.DetailViewController.NavigationItem.SetLeftBarButtonItem (new UIBarButtonItem(UIBarButtonSystemItem.Stop, (sender, args) => {
controller.DetailViewController.NavigationController.PopViewController(true);
}), true);
Its written in C# using mono touch, and Xamarin.iOS, but I can work on porting Objective-c/Swift code if needed. Im just stuck at this point and can't seem to figure it out at all.
If you push your view controller then you will get default back button with navigation bar. If you don't want to push to push viewController then you need to add it on storyBoard. For pushing the view controller you write the code as
Your_ViewController *viewController = [self.storyboard instantiateViewControllerWithIdentifier:#"Your_ViewController"];
[self.navigationController pushViewController:viewController animated:YES];
I have pushpins on my map in Visual Studio (below is the code that does this). But they are blue dots. I want to change my pushpins to something else besides blue dots. I found this website that gives a bunch of syntax of pushpins. (http://msdn.microsoft.com/en-us/library/ff701719.aspx) Currently, it displays the pushpin as number 77. I don't know if this is the default pushpin, or what. But I want to change it to something else like 71 so it gives more information. Any idea how I can do this with my code I have below?
Thanks!! :)
private async void PopulateMap()
{
//put data on map
LocationCollection locationCollection = new LocationCollection();
if (_group != null)
{
foreach (SampleDataItem item in _group.Items)
{
Pushpin myPushpin = new Pushpin();
myPushpin.Text = item.Title;
//created new location
Location rentLocation = new Location(Convert.ToDouble(item.Latitude), Convert.ToDouble(item.Longitude));
MapLayer.SetPosition(myPushpin, rentLocation);
rentalMap.Children.Add(myPushpin);
locationCollection.Add(rentLocation);
}
}
The documentation you referenced is for the Static imagery API and those pushpins are not available outside of that service. That said it's very easy to create custom pushpins. If you simply want to change the color try using the background property of the Pushpin class. Alternatively you can create a custom style that has a DataTemplate and apply that to the pushpin. If you simply want to use an image as a pushpin you can create an Image object, or any UIElement and add it to the map the same way you do a pushpin.
I'm assuming you are creating a Windows 8 app. If so, take a look at my free ebook on crating location intelligent windows store apps. In chapter 4 I show how to create custom pushpins: http://rbrundritt.wordpress.com/my-book/
You can also find all the code samples for the book here: http://code.msdn.microsoft.com/Location-Intelligence-for-1c691d0e
I finished to develop an XNA game, then I created the Monogame project, and tested it on my device. Now I made some other pages such as an "about" page. How can I go to that page considering I have a Monogame project and just an XNA code? In particular inside my game I made a Main Menu where you can click the "about" button and know if someone has clicked: how can I link that event to the "go to about.xaml" function?
Inside XNA, update method:
if (about_button.IsClicked())
{
// Go to about.xaml
}
I tried:
if (about_button.IsClicked())
{
((PhoneApplicationFrame)Application.Current.RootVisual).Navigate(new Uri("/About.xaml", UriKind.Relative));
}
But it throws: System.UnauthorizedAccessException
I haven't tried this myself, but the WP framework has the Window.Current.Content object which you can use to load different views.
For example:
// Create a Frame to act navigation context and navigate to the first page
var rootFrame = new Frame();
rootFrame.Navigate(typeof(BlankPage));
// Place the frame in the current Window and ensure that it is active
Window.Current.Content = rootFrame;
Window.Current.Activate();
So if you are using a windows phone 8 project template, with that object you can easily tell the application to load a xaml view or the game one.
You can also check how to do it with WinRT and monogame on this site (the Window.Current is part of the WP and WinRT framework). Here, you will find how to integrate both frameworks in order to create a monogame using the WinRT xaml views :)
For more information on the Window.Current, check this link.
EDIT
If you used a monogame for windows phone template, a XAML page should already exist in your project which is used to load the game itself, as well as a media element for video and sound playback.
The page is called "GamePage.xaml", which you could use for your navigational purposes.
This info was taken from the "Windows 8 and Windows Phone 8 Game Development" book written by Adam Dawes (chapter 13).
In the case of the Windows Phone projects, GamePage is implemented as
a normal page. [...]
Within the Windows Phone page is a full-page
Grid control, inside which is another full-screen control of type
DrawingSurface. This is a type of control that DirectX can use to
render graphics to a Windows Phone page. Our XAML content can also be
placed into the Grid. A MediaElement control is present within the
Grid, too. MonoGame uses this for some of its audio playback
functionality.
On both platforms, the way that XAML and DirectX have been designed to
interact is that the DirectX rendering is processed first. Once this
has been completed, the XAML renderer then takes control and adds its
content as a second step, prior to presenting the final rendered page
to the user. As a result, XAML content will always appear in front of
any graphics rendered by MonoGame. This ensures that any XAML controls
we use as our user interface (for control buttons, text displays, and
so on) will appear unobstructed in front of the game graphics.
The XAML rendering still takes any transparency within the controls
into account, so it is quite possible to have controls that are
partially transparent or that use alpha shading. These will blend in
front of the MonoGame graphics, as you would expect them to.
With this into account, you should be able to throw an event from your game class (monogame), the xaml page can suscribe itself to it and then, when captured, render your xaml page (maybe a user control would be wiser as you won't navigate away from the main game page).
Hopefully, this will help you with your problem.
Try to create a frame in your gamepage
public static Frame RootFrame { get; private set; }
then in your click event put these lines
RootFrame = new Frame();
RootFrame.Navigate(typeof(about));
did this work?
You receive that error because the call has to be made from the UI thread like this:
Deployment.Current.Dispatcher.BeginInvoke(() =>
(App.Current.RootVisual as PhoneApplicationFrame).Navigate(new Uri("/Pages/MenuPage.xaml", UriKind.Relative)));
Also, make sure you dispose of the game object when unloading the game xaml page. You to this by subscribing to the Unloaded event of the GamePage and calling Dispose on the game object. See below:
public partial class GamePage : PhoneApplicationPage
{
private LoonieGame _game;
public GamePage()
{
InitializeComponent();
_game = XamlGame<LoonieGame>.Create("", this);
this.Unloaded += GamePage_Unloaded;
}
void GamePage_Unloaded(object sender, RoutedEventArgs e)
{
Deployment.Current.Dispatcher.BeginInvoke(() => _game.Dispose());
}
}
i want to make Form loading a splash screen with transparent background and a non rectangular shape with is click-through-able. is this possible ? how it's made ?
i was wondering if there is a way of making the Form1 calling a WPF window ( as a kind of splash screen ) within the same vs project.
i've tryed to rightclick the project in the project-explorer in VS -> add and then i was searching for WPF window. but the only thing that i am able to add is a "wpf User Controll".
so far so good, but if i start the application then, it gives me an error saying i should ad a reference to System.Windows.markup.IQueryAmbient, but i cant find it in the list ( .NET )
what am i doing wrong ? what is the propper way to implement a WPF window into a Forms application project ?
thanks for all suggestions.
EDIT:
this is the splash screen of Adobe Flash Professional CS6, and it pretty much explains exactly what i want to have. a non rectangular image with semi-transparent and full-transparent parts in it
http://webalazar.com/wp-content/uploads/2012/09/Adobe-Flash-Professional-CS6.png
There's 3 ways to do this:
1.) go completely WPF and then reference the WinForms .NET libraries in your WPF application if you want WinForms specific stuff
2.) Create a new WPF library (a .NET dll that can be referenced in your code) that has all the WPF functionality you want in it (like your splash screen), then create a new WinForms .NET app and reference the WPF project in your WinForms project then call your WPF library from your WinForms app
3.) Depending on what your trying to accomplish (like special graphics windows or other 'fancy' UI stuff), and how much time/effort you're willing to put into it, you could learn DirectX, or use the 'gdi32.dll' and import it's GDI+ functionality.
EDIT:
So here's a step by step to get a WPF splash screen in a WindowForm C# app:
1.) Create a new C# Windows Forms appliction, call it whatever you want and save it wherever you want
2.) File->Add->New Project
3.) Add a new C# WPF User Control Library, call it SplashScreen and be sure to note that it will try and save it under the same file location, so if you want to save it else where be sure to choose a different location.
4.) Delete the default 'UserControl1.xaml' that's created in the SplashScreen WPF library
5.) Right click the WPF project and 'Add->Window', then name it SplashScreen.xaml
6.) Replace all of the exisiting code in SplashScreen.xaml with the following:
<Window x:Class="SplashScreen.SplashScreen"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
WindowStyle="None" Background="Transparent" AllowsTransparency="True"
ShowInTaskbar="False" SizeToContent="WidthAndHeight"
Title="SplashScreen" WindowStartupLocation="CenterScreen">
<Image Source="logo.png" Stretch="None" />
</Window>
7.) Right click the WPF project and 'Add->Existing Item', make sure your file filter is set to 'all files' and choose your 'logo.png'.
8.) View the properties of the newly imported 'logo.png' and make sure its 'Build Action' is set to 'Resource'
9.) In your Windows Forms project right click 'Add->New Reference', select the 'Projects' tab and select the 'SplashScreen' WPF project you just created.
10.) In your Windows Forms project right click 'Add->New Reference', select the '.NET' tab and select the 'PresentationFramework','PresentationCore', 'WindowsBase' and 'System.Xaml' libraries.
11.) In your 'Program.cs' file in your Windows Forms project, you can now do this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace MyGame
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
// Create a new 'splash screen instance
SplashScreen.SplashScreen ss = new SplashScreen.SplashScreen();
// Show it
ss.Visibility = System.Windows.Visibility.Visible;
// Forces the splash screen visible
Application.DoEvents();
// Here's where you'd your actual loading stuff, but this
// thread sleep is here to simulate 'loading'
System.Threading.Thread.Sleep(5000);
// Hide your splash screen
ss.Visibility = System.Windows.Visibility.Hidden;
// Start your main form, or whatever
Application.Run(new Form1());
}
}
}
Create a Windows Form
set its FormBorderStyle to None
set its TransparencyKey to #00FF00
set its BackgroundImage to a png image with unwanted area colors set to #00FF00
done!
when you load an image as background image for your form, it will compare every pixel of it with the transparency key, if it was a match, then it will render that pixel as transparent.