Samples on Pushpin infobox in windows phone 7 bing maps? - windows-phone-7

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

Related

How to update Preferences again after removing item to list in Xamarin

I have a list of CartUsers. I execute the command remove item from the list. I managed to remove each item in the list. However how does the list Preferences update.
My code:
cart.xaml
<StackLayout Padding="15,13" BindableLayout.ItemsSource="{Binding CartUsers}">
<BindableLayout.ItemTemplate>
<DataTemplate>
<StackLayout Margin="0,2.5" x:DataType="model:CartUser">
<Label Text="{Binding NumberProduct}" />
<ImageButton x:Name="removeitem" Clicked="removeitem_Clicked" >
<ImageButton.Source>
<FontImageSource Color="red" Size="10" FontFamily="FontAwesome" Glyph="{x:Static local:FontAwesomeClass.TrashAlt}"/>
</ImageButton.Source>
</ImageButton>
</StackLayout>
</DataTemplate>
</BindableLayout.ItemTemplate>
</StackLayout>
2.cart.xaml.cs
CartUserViewModel cartUserViewModel;
private void removeitem_Clicked(object sender, EventArgs e)
{
var mycart = Preferences.Get("CartUser", "defaultcart");
var getcart = JsonConvert.DeserializeObject<List<CartUser>>(mycart);
var button = sender as ImageButton;
var itemcart = button.BindingContext as CartUser;
cartUserViewModel.RemoveItemCart.Execute(itemcart);
//Preferences.Set("CartUser", JsonConvert.SerializeObject(getcart));
}
Update...
private void removeitem_Clicked(object sender, EventArgs e)
{
var mycart = Preferences.Get("CartUser", "defaultcart");
var getcart = JsonConvert.DeserializeObject<List<CartUser>>(mycart);
var button = sender as ImageButton;
var itemcart = button.BindingContext as CartUser;
cartUserViewModel.RemoveItemCart.Execute(itemcart);
getcart.Remove(itemcart);
int count = getcart.Count();
Preferences.Set("CartUser", JsonConvert.SerializeObject(getcart));
}
You just deleted a CartUser inside the ViewModel, and the Preferences have not changed.
According to your code, getcart is the List obtained using Preferences. You need to use getcart.Remove(itemcart); to delete an item. Then use your commented code to store it.

How to know which indicator you are on with CarouselView in Xamarin Forms?

I a using the CarouselView and I can successfully load in items! Yey, so far so good. But now when i reach the 2nd item, I try to do a specific function that will only happen in the 2nd index.
Right now i seem to have figured out when im on the 2nd page al though the log is writing a lot of things in the log, but when i transition to the 3rd page, or back to the 1st page, i have lost count (programmatically) of where I am.
<CarouselView BackgroundColor="Transparent"
HorizontalScrollBarVisibility="Never"
IndicatorView="indicatorView"
VerticalOptions="CenterAndExpand"
Margin="25,0"
Scrolled="CarouselView_Scrolled"
ItemsSource="{Binding BindingContext.Intro, Source={x:Reference ParentView}}">
<CarouselView.ItemsLayout>
<LinearItemsLayout Orientation="Horizontal"
SnapPointsAlignment="Center"
SnapPointsType="MandatorySingle"/>
</CarouselView.ItemsLayout>
<CarouselView.ItemTemplate>
<DataTemplate>
<Label Text="{Binding Text}"
FontSize="Large"
HorizontalTextAlignment="Start"
FontFamily="Helvetica Neue"
TextColor="DimGray"
FontAttributes="None" />
</AbsoluteLayout>
</DataTemplate>
</CarouselView.ItemTemplate>
</CarouselView>
Code behind:
async void CarouselView_Scrolled(System.Object sender, Xamarin.Forms.ItemsViewScrolledEventArgs e)
{
System.Diagnostics.Debug.WriteLine(e.CenterItemIndex);
if (e.CenterItemIndex == 1)
{
if (Transitioning == false)
{
Transitioning = true;
await ParentView.ColorTo(Color.White, Color.FromHex("#161825"), c =>
{
ParentView.BackgroundColor = c;
Transitioning = false;
}, 500);
}
}
else
{
Transitioning = true;
await ParentView.ColorTo(Color.FromHex("#161825"), Color.White, c => ParentView.BackgroundColor = c, 500);
Transitioning = false;
}
}
What logic do i need to add in my frontend to successfully monitor if im on page 2?
ItemsViewScrolledEventArgs has a CenterItemIndex property that tells you which item is in the center view
or you could use the CurrentItemChanged event

How can I get the text of the 1st label inside of a grid in CS?

I have this XAML code:
<ViewCell >
<Grid VerticalOptions="CenterAndExpand" x:Name="abc" Tapped="atiSelectValueX" >
<local:StyledLabel Text="{Binding [0].Name}" HorizontalOptions="StartAndExpand" />
<local:StyledLabel IsVisible="{Binding [0].IsSelected}" TextColor="Gray" HorizontalOptions="End" Text="x" />
</Grid>
</ViewCell>
and this CS:
void atiSelectValueX(object sender, EventArgs e)
{
var grid = sender as Grid;
if (grid == null)
return;
var label = grid.Children. << trying to get the Text value
Can someone show me how I can get the value of the text for the first label? I tried some ideas using LINQ and getting the First or using a Where but for each I tried I still was not able to add .Text as I think somehow I need to cast the value to being a label so I can use label.Text
You can test it via the is statement:
var label = grid.Children.FirstOrDefault(_ => _ is Label) as Label;
var textValue = label?.Text;
Update: Or use Linq's OfType<T> (thanks to #Cheesebaron for the comment)
var label = grid.Children.OfType<Label>().FirstOrDefault();

wp7 listbox selection

I have a listBox with 1000+ items.
in xaml
<ListBox
//some code here
SelectionChanged="OnSelectionChanged">
<ListBox.ItemTemplate>
<DataTemplate>
<controls:MyCustomItem/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
In cs
private void OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
var item = lb.SelectedItem as MyCustomItem;
var vm = DataContext as ViewModel;
if (vm == null) return;
foreach (var it in vm.ItemsForBinding)
{
it.IsSelected = false;
}
item .IsSelected = true;
}
in MyCustomItem xaml
<UserControl
//Some code here
Style="{Binding Path=IsSelected, Converter = {StaticResource BoolToStyle}}">
<Border
</Border>
</UserControl>
Where IsSelected - one of property of my ViewModel. Converter return one of two style (first if item selected, second - if no)
Always work, but I know - it's very resource-intensive, and the wrong decision.
How to do it right?
This post help me!
Just override default ItemContainerStyle for my ListBox.
I removed:
metod OnSelectionChanged, UserControl MyCustomItem, converter for styles and
<ListBox.ItemTemplate>
<DataTemplate>
<controls:MyCustomItem/>
</DataTemplate>
</ListBox.ItemTemplate>
from xaml.

view gif image in image UI control windows phone 7

I want to display the gif image in the UI image control.
I have Image image1;
image1.source = new BitmapImage(new Uri(link, UriKind.Absolute));
but the link in Uri is a .gif image.
I have read this: imagetool however I still not get it how to use the library. I did download the library and add references, then from that I'm stuck, I want to set source in code.
Can you help explains it a little bit more?
My code currently like this:
<UserControl.Resources>
<imagetools:ImageConverter x:Key="ImageConverter" />
</UserControl.Resources>
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid HorizontalAlignment="Right" Width="69">
<Border BorderBrush="White" BorderThickness="3" CornerRadius="7" Background="Black">
<Image Width="69" Height="69" Name="canvasImage" Stretch="UniformToFill" HorizontalAlignment="Center" VerticalAlignment="Center" ImageFailed="canvasImage_ImageFailed" />
</Border>
<Border BorderBrush="White" BorderThickness="3" CornerRadius="7" Background="Black">
<imagetools:AnimatedImage Name="canvasGifImage" Width="69" Height="69" Stretch="UniformToFill" HorizontalAlignment="Center" VerticalAlignment="Center" />
</Border>
</Grid>
</Grid>
In my MainPage.xaml.cs, because I don't know whether it is an png/jpg or a gif, so I have it try to load png/jpg first, if failed then try load gif in the imagetools control name canvasGifImage:
private void DisplayImage(int index, string link)
{
try
{
control1.canvasImage.Source = new BitmapImage(new Uri(link, UriKind.Absolute));
}
catch //if fail to load image as normal, do this
{
//but I dont know how to set Source for the canvasGifImage, help me here:
control1.canvasGifImage.Source = *new BitmapImage(new Uri(link, UriKind.Absolute));*
}
}
Replace the use of the ManualResetEvent for async code.
using (var resetEvent = new ManualResetEvent(false))
{
ImageTools.IO.Decoders.AddDecoder<GifDecoder>();
var extendedImage = new ExtendedImage();
extendedImage.LoadingCompleted += (s, e) => resetEvent.Set();
extendedImage.LoadingFailed += (s, e) => resetEvent.Set();
extendedImage.SetSource(gifStream);
resetEvent.WaitOne(TimeSpan.FromSeconds(5));
// Check for timeout or error
var enc = new JpegEncoder();
var jpegStream = new MemoryStream();
enc.Encode(extendedImage, jpegStream);
...
}

Resources