Add a pushpin on Windows phone 8 map - vb.net

does anyone know how to put a pushpin on Windows Phone 8 maps API?
I find only code to add a pushpin to a bing map..
I prefer only XAML code, if possible.
Thanks

This is what I use.. the commented out code will give you a round marker, the default pushpin is squarish..
<Grid x:Name="ContentPanel" Margin="12,0,12,0">
<maps:Map x:Name="MapControl">
</maps:Map>
</Grid>
private void DisplayMapPoint()
{
MapControl.Layers.Clear();
var MyGeo = new GeoCoordinate(_Latitude, _Longitude);
MapControl.Center = MyGeo;
MapControl.ZoomLevel = 14;
DrawMapMarker();
}
private void DrawMapMarker()
{
var Overlay = new MapOverlay
{
GeoCoordinate = MapControl.Center,
//Content = new Ellipse
//{
// Fill = new SolidColorBrush(Colors.Red),
// Width = 40,
// Height = 40
//}
Content = new Pushpin
{
GeoCoordinate = MapControl.Center,
Background = new SolidColorBrush(Colors.Red),
Content = _SiteName
}
};
var Layer = new MapLayer {Overlay};
MapControl.Layers.Add(Layer);
}
This link may also help:
http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj207037(v=vs.105).aspx

Related

how to convert WebView into IRandomAccessStream in UWP?

What i have Tried is?
My Xaml code :
<Grid x:Name="MyGrid">
<Button x:Name="but" Content="Click" Click="but_Click"></Button>
</Grid>
My C# code:
private async void but_Click(object sender, RoutedEventArgs e)
{
WebView x = new WebView();
x.Width = 100; x.Height = 100;
InMemoryRandomAccessStream ms = new InMemoryRandomAccessStream();
await x.CapturePreviewToStreamAsync(ms);
}
when I try to convert Webview to Stream.It throws an error like this.
I don't why this was happening .Can Anyone suggest me , How to convert webview to IRandomAccessstream?
The problem is the WebView has not rendered into xaml visual tree. we need to insert WebView into Page content before calling CapturePreviewToStreamAsync method.
private WebView x;
public MainPage()
{
this.InitializeComponent();
x = new WebView();
x.Height = 100; x.Width = 100;
RootGrid.Children.Add(x);
}
private async void bookmarkBtn_Click(object sender, RoutedEventArgs e)
{
InMemoryRandomAccessStream ms = new InMemoryRandomAccessStream();
await x.CapturePreviewToStreamAsync(ms);
}

Trying to stop SpeechSynthesizer in uwp on click of a button

I'm trying to stop SpeechSynthesizer in uwp on click of a button and also trying to start SpeechSynthesizer on clicking same icon again.Any Help would be appreciated for resolution of this issue.
XAML
<Image x:Name="Sound" Source="ABCD/sound_active.png"
RelativePanel.AlignBottomWithPanel="True"
RelativePanel.RightOf="Pause" Tapped="SoundTap"
Margin="17,0,0,0"
Width="40" Height="40"/>
C# code
private void SoundTap(object sender, TappedRoutedEventArgs e)
{
if ((Sound.Source as BitmapImage).UriSource == new Uri("ms-appx:///ABCD/Sound_active.png", UriKind.Absolute))
{
Sound.Source = new BitmapImage(new Uri("ms-appx:///ABCD/Sound_mute.png"));
textToSpeech.Stop();
}
else
{
Sound.Source = new BitmapImage(new Uri("ms-appx:///ABCD/Sound_active.png"));
textToSpeech.Play();
}
}
public async void Prevevent(object sender, TappedRoutedEventArgs e)
{
currentIndex--;
if (currentIndex < 0)
{
currentIndex = 0;
return;
}
Alph_cap.Source = new BitmapImage(new Uri("ms-appx:///ABCD/Cap_alpha/Cap_" + currentIndex + ".png"));
Alph_small.Source = new BitmapImage(new Uri("ms-appx:///ABCD/Cap_alpha/Sml_" + currentIndex + ".png"));
CapAlphaName.Text = CapsAlpha[currentIndex];
SmallAlphaName.Text = SmallAlpha[currentIndex];
var speechText = this.CapAlphaName.Text;
if (speechText != "")
{
var synth = new SpeechSynthesizer();
var speechStream =await synth.SynthesizeTextToStreamAsync(speechText);
this.textToSpeech.AutoPlay = true;
this.textToSpeech.SetSource(speechStream, speechStream.ContentType);
this.textToSpeech.Play();
}
}
Understanding the question:
Basically you're looking for a toggle switch to turn on and turn off the speech synthesis tts(Text to Speech) in simpler terms.
The Solution:
This couldn't have been simpler enough, never the less, this is how you do it.
Create a Bool property, eg: private IsTTSEnabled = false we'll use this as a flag.
On your Image tap or click, check the current value of IsTTSEnabled and flip it (false if true or true if false) eg: IsTTSEnable = !IsTTSEnable;
Now put a if loop for handling if the TTS is turned on or if it's turned off. Also, since TTS is done using a media element, you don't need to reInitialize your TTS, simple pause and play your media element or start and Stop it as per needs.
So your c# code becomes:
private bool IsTTSEnabled = false;
private void SoundTap(object sender, TappedRoutedEventArgs e)
{
IsTTSEnabled = !IsTTSEnabled;
if(IsTTSEnabled)
{
Sound.Source = new BitmapImage(new Uri("ms-appx:///ABCD/Sound_mute.png"));
textToSpeech.Stop();
}
else
{
Sound.Source = new BitmapImage(new Uri("ms-appx:///ABCD/Sound_active.png"));
textToSpeech.Play();
}
}
Note: This functionality can be easily implemented using Data Binding to provide scalability and ease of management but then the simpler way to do so is like the one I've illustrated

How to save a grid as a bitmap Image in the local storage in windows 8

I am very new to Windows 8 application development. I am developing an application which requires to save a grid as Bitmap Image in local storage.
I have tried by using writable bitmap but i didn't get the solution.
Then I searched for the samples but I got the answer as a 'Not possible'. But in some answers I found that By using 'WriteableBitmapEx' we can do that. But I do not know how to implement this by using this library. If any one knows about that please reply me.
Thanks in advance.
EDITED.
<Canvas Background="Cyan" Name="panelcanvas" Margin="47.5,57,327.5,153"
Width="200"
Height="400">
<Image Name="maskimg"
Height="100" Width="220"/>
<ScrollViewer ZoomMode="Enabled" Name="scroll">
<Image Name="img" Stretch="Fill" Canvas.Top="15"
Height="400" Width="200" Source="mask_image.png">
<Image.RenderTransform>
<CompositeTransform x:Name="Composite_Transform"></CompositeTransform>
</Image.RenderTransform>
</Image>
</ScrollViewer>
</Canvas>
<Image Name="maskimg2" HorizontalAlignment="left" Width="200"
Height="400"/>
<Image Name="maskimg3" HorizontalAlignment="Right" Width="200"
Height="400"/>
C# code.
var destBmp = BitmapFactory.New((int)panelcanvas.ActualWidth, (int)panelcanvas.ActualHeight);
foreach (var child in panelcanvas.Children)
{
var img = child as Image;
if (img != null)
{
var sourceMask = ((BitmapImage)img.Source);
var sourceUriMask = sourceMask.UriSource;
Uri imageUri = new Uri(strMask.ToString());
var srcBmp = await new WriteableBitmap(1, 1).FromContent(imageUri);
if (srcBmp != null)
{
var x = Canvas.GetLeft(img);
var y = Canvas.GetTop(img);
destBmp.Blit(new Rect(x, y, srcBmp.PixelWidth, srcBmp.PixelHeight), srcBmp, new Rect(0, 0, srcBmp.PixelWidth, srcBmp.PixelHeight));
}
}
await WriteableBitmapToStorageFile(destBmp, FileFormat.Jpeg);
private async Task<StorageFile> WriteableBitmapToStorageFile(WriteableBitmap WB, FileFormat fileFormat)
{
string FileName = "MyFile.jpeg";
StorageFolder localFolder = ApplicationData.Current.LocalFolder;
var file = await localFolder.CreateFileAsync(FileName, CreationCollisionOption.ReplaceExisting);
using (IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.ReadWrite))
{
BitmapEncoder encoder = await BitmapEncoder.CreateAsync(BitmapEncoderGuid, stream);
Stream pixelStream = WB.PixelBuffer.AsStream();
byte[] pixels = new byte[pixelStream.Length];
await pixelStream.ReadAsync(pixels, 0, pixels.Length);
encoder.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Ignore,
200,
200,
0,
0,
pixels);
await encoder.FlushAsync();
}
return file;
}
This blog posts point out what you need to do using the WriteableBitmapEx lib. Note the required RenderTargetBitmap was introduced with Windows 8.1! For Windows 8.0 this is not possible at all.
http://kodierer.blogspot.de/2013/12/easy-render-writeablebitmapex-with.html
http://kodierer.blogspot.de/2013/12/how-to-encode-and-save-writeablebitmap.html
Here's a code snippet:
// Render some UI to a RenderTargetBitmap
var renderTargetBitmap = new RenderTargetBitmap();
await renderTargetBitmap.RenderAsync(MyGrid);
// Get the pixel buffer and copy it into a WriteableBitmap
var pixelBuffer = await renderTargetBitmap.GetPixelsAsync();
var width = renderTargetBitmap.PixelWidth;
var height = renderTargetBitmap.PixelHeight;
WriteableBitmap wbmp = await new WriteableBitmap(1, 1).FromPixelBuffer(pixelBuffer, width, height);
SaveWriteableBitmapAsJpeg(wbmp, "mygrid.jpg");
private static async Task SaveWriteableBitmapAsJpeg(WriteableBitmap bmp, string fileName)
{
// Create file in Pictures library and write jpeg to it
var outputFile = await KnownFolders.PicturesLibrary.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting);
using (var writeStream = await outputFile.OpenAsync(FileAccessMode.ReadWrite))
{
await EncodeWriteableBitmap(bmp, writeStream, BitmapEncoder.JpegEncoderId);
}
return outputFile;
}
private static async Task EncodeWriteableBitmap(WriteableBitmap bmp, IRandomAccessStream writeStream, Guid encoderId)
{
// Copy buffer to pixels
byte[] pixels;
using (var stream = bmp.PixelBuffer.AsStream())
{
pixels = new byte[(uint) stream.Length];
await stream.ReadAsync(pixels, 0, pixels.Length);
}
// Encode pixels into stream
var encoder = await BitmapEncoder.CreateAsync(encoderId, writeStream);
encoder.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied,
(uint) bmp.PixelWidth, (uint) bmp.PixelHeight,
96, 96, pixels);
await encoder.FlushAsync();
}

Create Application bar dynamically

I want to create Application Bar dynamically in Windows Phone 8. I have used the following code to create application bar in appbar.cs file
class AppBar
{
public AppBar()
{
ApplicationBar appbar;
this.appbar = new ApplicationBar();
this.appbar.IsVisible = true;
this.appbar.Opacity = 1;
this.appbar.Mode = ApplicationBarMode.Minimized;
ApplicationBarIconButton appButon = new ApplicationBarIconButton();
appButon.IconUri = new Uri("/images/show.png", UriKind.Relative);
appButon.Text = "Show";
this.appbar.Buttons.Add(appButon);
appButon.Click += appButon_Click;
}
}
void appButon_Click(object sender, EventArgs e)
{
}
}
If i have created the instance of AppBar class, then all the methods called but i unable to see the application bar. I have given request to create the appbar from webview. From the javainterface i have created the instance of application bar with the given text and icon. How to show this in the web page.
I have solved the my Application bar issue. Added my application bar with parent element(PhoneApplicationPage).
class AppBar
{
public AppBar()
{
ApplicationBar appbar;
PhoneApplicationPage parentpage = (Application.Current.RootVisual as ContentControl).Content as PhoneApplicationPage;
parentpage.ApplicationBar = new ApplicationBar();
appbar = parentpage.ApplicationBar;
appbar.IsVisible = true;
appbar.Opacity = 1;
appbar.Mode = ApplicationBarMode.Minimized;
ApplicationBarIconButton appButon = new ApplicationBarIconButton();
appButon.IconUri = new Uri("/images/show.png", UriKind.Relative);
appButon.Text = "Show";
appbar.Buttons.Add(appButon);
appButon.Click += appButon_Click;
}
}
void appButon_Click(object sender, EventArgs e)
{
}
}

Opening context menu just above item in win 8 metro app

I have a list of items defined in a ListView. When user click or tap any item, I want to show a PopupMenu just above the selected Item. How should I position the PopupMenu?
varmenu =newPopupMenu();
menu.Commands.Add(
newUICommand("Remove", (x) =>
{...
// Create the message dialog and set its content
}, 1));
var chosenCommand =awaitmenu.ShowForSelectionAsync(GetElementRect((FrameworkElement)sender));
Rect GetElementRect(FrameworkElement element)
{
GeneralTransform buttonTransform = element.TransformToVisual(null);
Pointpoint = buttonTransform.TransformPoint(newPoint());
returnnewRect(point,newSize(element.ActualWidth, element.ActualHeight));
}
This is the code I've been using to open up a popup menu above a button in an app bar.
private async void OnOpenMenu(object sender, RoutedEventArgs e)
{
var button = (Button)sender;
var transform = button.TransformToVisual(this);
var point = transform.TransformPoint(new Point(0, 0));
var menu = new PopupMenu();
menu.Commands.Add(new UICommand("Menu Item 1"));
menu.Commands.Add(new UICommand("Menu Item 2"));
await menu.ShowAsync(point);
}