implementing the Bing maps in Windows phone 7 - windows-phone-7

I am new to the Windows phone 7, Please help me
<phone:PhoneApplicationPage
x:Class="Sample1.PanoramaPage1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="800"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="False"
xmlns:m="clr-namespace:Microsoft.Maps.MapControl;assembly=Microsoft.Maps.MapControl"
xmlns:my="clr-namespace:Microsoft.Phone.Controls.Maps;assembly=Microsoft.Phone.Controls.Maps">
<my:Map x:Name="map1" CredentialsProvider="{Binding CredentialsProvider}" Height="462" HorizontalAlignment="Left" Margin="6,6,0,0" VerticalAlignment="Top" Width="444" >
<my:MapItemsControl x:Name="mapItemsControl" ItemsSource="{Binding Path=Locations}">
<my:MapItemsControl.ItemTemplate>
<DataTemplate>
<m:Pushpin MouseLeftButtonUp="Pushpin_MouseLeftButtonUp" Background="Red" Location="{Binding}">
</m:Pushpin>
</DataTemplate>
</my:MapItemsControl.ItemTemplate>
</my:MapItemsControl>
</my:Map>
And my .xaml.cs is like this:
public PanoramaPage1()
{
InitializeComponent();
//map1.Mode = new RoadMode();
Pushpin pushpin = new Pushpin();
Location location = new Location();
location.Latitude = 53.550556;
location.Longitude = 9.993333;
pushpin.Location = location;
pushpin.Background = new SolidColorBrush(Colors.Red);
map1.Children.Add(pushpin);
}
if we see i have two(2) map control are added to the page those are
xmlns:m="clr-namespace:Microsoft.Maps.MapControl;assembly=Microsoft.Maps.MapControl"
xmlns:my="clr-namespace:Microsoft.Phone.Controls.Maps;assembly=Microsoft.Phone.Controls.Maps"
if i use the map of the Microsoft.Maps.MapControl pushpin is working but the below code is not working.
<m:Map.Mode>
<m:AerialMode ShouldDisplayLabels="True" />
</m:Map.Mode>
it is giving error as "The property 'ShouldDisplayLabels' was not found in type 'AerialMode'."
If i use map of the Microsoft.Phone.Controls.Maps then Pushpin is not working means pushpin staying stable when we are moving the map(map is moving but pushpin is staying satble). And also if add the two pushpins like below:
public PanoramaPage1()
{
InitializeComponent();
//map1.Mode = new RoadMode();
GeoCoordinate lHamburg = new GeoCoordinate(53.550556, 9.993333);
Pushpin pushpin = new Pushpin();
Location location = new Location();
location.Latitude = 53.550556;
location.Longitude = 9.993333;
pushpin.Location = location;
pushpin.Background = new SolidColorBrush(Colors.Red);
map1.Children.Add(pushpin);
pushpin = new Pushpin();
location = new Location();
location.Latitude = 83.550556;
location.Longitude = 9.993333;
pushpin.Location = location;
pushpin.Background = new SolidColorBrush(Colors.Yellow);
map1.Children.Add(pushpin);
}
only second pushpin(Colors.Yellow) i am able to see on the map.
Please help me out.

You have two instances with the names 'pushpin'

Related

UWP XAML ImageBrush.imageSource from networkshare

i edited my question:
i have a stack panel with buttons from array.
now I want to set the Button Background from networkshare images.
here ist my source code:
XAML:
<Page
x:Class="App4.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App4"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" Height="1205.722" Width="2045.722">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" Margin="0,0,0,0">
<StackPanel x:Name="sp" HorizontalAlignment="Left" Height="1070" Margin="10,10,0,0" VerticalAlignment="Top" Width="145" Padding="0" CornerRadius="10" RequestedTheme="Light" ScrollViewer.HorizontalScrollBarVisibility="Visible" Grid.RowSpan="2">
<FlyoutBase.AttachedFlyout>
<MenuFlyout/>
</FlyoutBase.AttachedFlyout>
</StackPanel>
</Grid>
Behind Code:
private void onLoad()
{
for (int i = 0; i < imgNames.Length; ++i)
{
ImageBrush brush1 = new ImageBrush();
brush1.ImageSource = new BitmapImage(new Uri("ms-appx:///assets/" + imgNames[i]));
Button button = new Button()
{
Content = string.Format(""),
Tag = i
};
button.Width = 100;
button.Height = 100;
button.Background = brush1;
button.Margin = new Thickness(0, 20, 0, 0);
button.Click += new RoutedEventHandler(button_Click);
this.sp.Children.Add(button);
}
}
Thanks
For loading image from network source you need to use these capabilities in your app
<Capabilities>
<Capability Name="internetClient" />
<Capability Name="privateNetworkClientServer" />
<Capability Name="internetClientServer" />
<uap:Capability Name="enterpriseAuthentication" />
</Capabilities>
and your image
<Image Name="YourImageElementName" />
and loading image in code behind
StorageFolder folder = await StorageFolder.GetFolderFromPathAsync(#"\\Your Image Full Path e.g user\folder\subfolder");
StorageFile file = await folder.GetFileAsync("ImageName.jpg");
using (var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read))
{
BitmapImage bitmap = new BitmapImage();
bitmap.SetSource(stream);
YourImageElementName.Source = bitmap;
}
Github sample i created for this https://github.com/shubdragon/LoadNetworkImageRepo
Points need to noted
1) You need to set your network location in code and image name with required extension.
2) must share that location to homegroup.
3) Note code behind in different pages and Package.appxmanifes (view it as code in xml editor)

Message box for getting ratings on number of launch for wp7

Recently I have been trying to add a message box that should be popped in some interval of time(ex. number of app launch). This message box can also be hidden permanently from popping out.
The following block of code can be dropped into any existing application and helps provide the above functionality:
In .xaml page,
<phone:PhoneApplicationPage
x:Class="App.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="800"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
xmlns:System="clr-namespace:System;assembly=mscorlib"
SupportedOrientations="Portrait" Orientation="Portrait"
Loaded="PhoneApplicationPage_Loaded"> **//Don't forget to add this code on your xaml page**
In .xaml.cs page,
public partial class MainPage : PhoneApplicationPage
{
private static bool PerformedRatingPromptCheck = false;
// Constructor
public MainPage()
{
InitializeComponent();
}
}
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
if (!PerformedRatingPromptCheck)
{
PerformedRatingPromptCheck = true;
int numAppLaunches = 0;
IsolatedStorageSettings.ApplicationSettings.TryGetValue<int>("Rating_numAppLaunches", out numAppLaunches);
int numNextRatingPrompt = 0;
if (!IsolatedStorageSettings.ApplicationSettings.TryGetValue<int>("Rating_numNextRatingPrompt", out numNextRatingPrompt))
{
numNextRatingPrompt = 3;
}
if (numAppLaunches >= numNextRatingPrompt)
{
IsolatedStorageSettings.ApplicationSettings["Rating_numNextRatingPrompt"] = numNextRatingPrompt * 2;
NotificationBox.ShowAgain("Enjoying the app?",
"Would you like to rate this app now, support us?",
"Ask me later",
false,
Surpressed => { },
"Rating_MsgPrompt",
new NotificationBoxCommand("yes", () => { new MarketplaceReviewTask().Show(); }),
new NotificationBoxCommand("no", () => { }));
}
IsolatedStorageSettings.ApplicationSettings["Rating_numAppLaunches"] = numAppLaunches + 1;
}
}
Source - Roybott Blog

Binding not working on custom UserControl in Windows Phone 7

I have a XAML UserControl which defines a fairly basic button - I want to define a Bindable property HasMeasurements which will display an overlay image when HasMeasurements is false . However when I include it in my project and bind it to the ViewModel it does not update consistently.
I am sure the ViewModel is properly notifying the bindings since I have simultenously bound the same ViewModel property to another separate element and it updates as expected. Also it works in Blend when I update the mock data.
I have tried this solution which defines a callback where I change the Visibility programatically, however this callback is not called every time the ViewModel property changes, only sometimes. I have also tried binding the Visibility in the XAML using this solution and a non dependency property which also did not work. I have also tried implementing NotifyPropertyChanged out of desperation but no luck there either ...
Here is my XAML,
<UserControl x:Class="MyApp.View.Controls.ConversionBtn"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
mc:Ignorable="d"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
d:DesignHeight="480" d:DesignWidth="480">
<Grid x:Name="LayoutRoot" Background="{StaticResource PhoneChromeBrush}">
<Grid x:Name="btnGrid" toolkit:TiltEffect.IsTiltEnabled="True" Height="115">
<Border Background="{StaticResource ImgOverlayColor}" BorderThickness="0" Padding="0" VerticalAlignment="Top" >
<TextBlock x:Name="titleTxtBlock" FontSize="{StaticResource PhoneFontSizeMedium}" Foreground="{StaticResource TileTxtColor}" Margin="6,0,0,0"/>
</Border>
<Image x:Name="notAvailableImg" Source="/Images/ConversionNotAvailableOverlay.png" HorizontalAlignment="Center" VerticalAlignment="Center" Stretch="None" />
</Grid>
</Grid>
</UserControl>
Here is the code behind,
// usings here ...
namespace MyApp.View.Controls
{
public partial class ConversionBtn : UserControl
{
public ConversionBtn()
{
InitializeComponent();
if (!TiltEffect.TiltableItems.Contains(typeof(ConversionBtn)))
TiltEffect.TiltableItems.Add(typeof(ConversionBtn));
//this.DataContext = this;
}
public string Title
{
get { return this.titleTxtBlock.Text; }
set { this.titleTxtBlock.Text = value; }
}
public static readonly DependencyProperty HasMeasurementsProperty =
DependencyProperty.Register("HasMeasurements", typeof(bool), typeof(ConversionBtn),
new PropertyMetadata(false, new PropertyChangedCallback(HasMeasurementsPropertyChanged)));
private static void HasMeasurementsPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
ConversionBtn cBtn = (ConversionBtn)d;
bool val = (bool)e.NewValue;
if (val)
{
cBtn.notAvailableImg.Visibility = Visibility.Collapsed;
}
else
{
cBtn.notAvailableImg.Visibility = Visibility.Visible;
}
cBtn.HasMeasurements = val;
}
public bool HasMeasurements
{
get { return (bool)GetValue(HasMeasurementsProperty); }
set { SetValue(HasMeasurementsProperty, value); }
}
}
}
You have a callback, that is called after HasMeasurment propetry was changed.
And in a callback you change it again. So, you have a logical misstake.
If you need to do something with this value - just save it in private field.
private static void HasMeasurementsPropertyChanged(DependencyObject d,
DependencyPropertyChangedEventArgs e)
{
ConversionBtncBtn = (ConversionBtn)d;
bool val = (bool)e.NewValue;
if (val)
{
cBtn.notAvailableImg.Visibility = Visibility.Collapsed;
}
else
{
cBtn.notAvailableImg.Visibility = Visibility.Visible;
}
cBtn.SetMeasurments(val);
}
private bool measurmentsState;
public void SetMeasurments(bool value)
{
measurmentsState = value;
}
Here you can get free e-Book by Charls Petzold about Windows Phone Development, there is a nice chapter about Dependency Properties.
Ah damnit, it was a combination of Anton's answer and the fact that I hadn't set my image as 'Content', hence it loaded in Blend but was not present in the deployed app.

Samples on Pushpin infobox in windows phone 7 bing maps?

How to show the info box when click on pushpins in windows phone 7?i.e when click on pushpin need to show some data and arrow button on the right side of data.please help me ...
when you click on pushpin at that time you display message box.
i.e In Your click event put message box.see bellow coding
pin[i] = new Pushpin();
pin[i].Location = new GeoCoordinate(Latitude, LongLatitude);
map1.Children.Add(pin[i]);
myCoorditeWatcher = new GeoCoordinateWatcher(GeoPositionAccuracy.High);
myCoorditeWatcher.MovementThreshold = 20;
var gl = GestureService.GetGestureListener(pin[i]);
gl.Tap += new EventHandler<GestureEventArgs>(GestureListener_Stack_Tap);
private void GestureListener_Stack_Tap(object sender, Microsoft.Phone.Controls.GestureEventArgs e)
{
for (int i = 0; i <= ClsGetDeviceMap.lstLongLatitude.Count - 1; i++)
{
if (sender.Equals(pin[i]))
{
MessageBox.Show(ClsGetDeviceMap.lstLocationName.ElementAt<string>(i).Trim());
MessageBox.Show(ClsGetDeviceMap.lstLatitude.ElementAt<string>(i).Trim());
MessageBox.Show(ClsGetDeviceMap.lstLongLatitude.ElementAt<string>(i).Trim());
}
}
}
You can customize your Pushpin
for example :
<my:Map Name="map1">
<my:Map.Resources>
<DataTemplate x:Key="pushpinTpl">
<my:Pushpin PositionOrigin="{Binding position}">
<my:Pushpin.ContentTemplate>
<DataTemplate>
<ToggleButton x:Name="togButt" >
<Grid>
<TextBlock Text="click"
Visibility="{Binding ElementName=togButt,Path=IsChecked,Converter={StaticResource BoolConverter},ConverterParameter=!}"/>
<TextBlock Text="alternative content"
Visibility="{Binding ElementName=togButt,Path=IsChecked,Converter={StaticResource BoolConverter}}"/>
</Grid>
</ToggleButton>
</DataTemplate>
</my:Pushpin.ContentTemplate>
</my:Pushpin>
</DataTemplate>
</my:Map.Resources>
<my:MapItemsControl ItemsSource="{Binding items}"
ItemTemplate="{StaticResource pushpinTpl}"
/>
</my:Map>
hope this help :)
There are alot of examples on the Bind sdk site:
http://www.bingmapsportal.com/isdk/ajaxv7

Getting noise when playing sound windows phone 7 emulator

I have a .wav music file.
When I tried to play using SoundEffect.Play();
mus1.Play(); I am getting noise rather than music.
The same is played well in PCs music player.
How to resolve this issue?
How to make sure that it will play good in Windows Phone 7 too?
It sounds like there's content in the .wav file that WP7 doesn't understand. Why don't you try converting it to .wav (yes I know it's already in .wav) as this may remove the unknown data.
Audacity (http://audacity.sourceforge.net/) is free and will do this for you. Just drag the .wav file into it and click file --> export...
Try the following Code
MainPage.xaml.cs
namespace MediaSample
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
progress.DataContext = this;
this.Loaded += new System.Windows.RoutedEventHandler(MainPage_Loaded);
mediaplayer.BufferingProgressChanged += new System.Windows.RoutedEventHandler(mediaplayer_BufferingProgressChanged);
mediaplayer.CurrentStateChanged += new RoutedEventHandler(mediaplayer_CurrentStateChanged);
}
public double Duration { get; set; }
void mediaplayer_CurrentStateChanged(object sender, RoutedEventArgs e)
{
if (mediaplayer.CurrentState == MediaElementState.Playing)
{
Duration = mediaplayer.NaturalDuration.TimeSpan.TotalSeconds;
ThreadPool.QueueUserWorkItem(o =>
{
while (true)
{
Dispatcher.BeginInvoke(new Action(() => Progress = mediaplayer.Position.TotalSeconds * 100 / Duration));
Thread.Sleep(0);
}
});
}
}
void mediaplayer_BufferingProgressChanged(object sender, System.Windows.RoutedEventArgs e)
{
MediaElement mediaplayer = sender as MediaElement;
if (mediaplayer.BufferingProgress == 1)
Debug.WriteLine(mediaplayer.NaturalDuration);
}
void MainPage_Loaded(object sender, System.Windows.RoutedEventArgs e)
{
mediaplayer.Source = new Uri("/Oru nalum..mp3", UriKind.Relative);
mediaplayer.Play();
}
public double Progress
{
get { return (double)GetValue(ProgressProperty); }
set { SetValue(ProgressProperty, value); }
}
// Using a DependencyProperty as the backing store for Progress. This enables animation, styling, binding, etc...
public static readonly DependencyProperty ProgressProperty =
DependencyProperty.Register("Progress", typeof(double), typeof(PhoneApplicationPage), new PropertyMetadata(0.0));
}
}
MainPage.xaml
<phone:PhoneApplicationPage
x:Class="MediaSample.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="True">
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock x:Name="ApplicationTitle" Text="Media Application" Style="{StaticResource PhoneTextNormalStyle}"/>
</StackPanel>
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<MediaElement x:Name="mediaplayer"/>
<ProgressBar Height="40" x:Name="progress" Value="{Binding Path=Progress}"/>
</Grid>
</Grid>
</phone:PhoneApplicationPage>
Add Mp3 file as follows,
Like that you can add .wav files. Working good. Tested codes above.
Thank you.
Use MeadiaElement Rather than using SoundEffect Class.
try this one
MediaElement

Resources