I want to bind my pushpins (which is a list ) to the My Map`s Maplayer.
There is no such thing "ItemSource" in MapLayers attributes. How can I bind my Pushpin List Data to MapLayer?
<my:Map HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Name="map1" CredentialsProvider="KEY" >
<my:Map.Children>
<my:MapLayer x:Name="pushPinMapLayer" ??Binding what???}">
</my:MapLayer>
</my:Map.Children>
</my:Map>
Please see the link below as it is from a question I asked a while back (which part of it should solve your question)
Binding Pushpins
I think the part that will help you the most is the Xaml (in the Map>ItemsControl element)
<my:Map Height="520" HorizontalAlignment="Left" Margin="6,6,0,0" Name="map1" VerticalAlignment="Top" Width="468" ZoomBarVisibility="Collapsed" ZoomLevel="1" CredentialsProvider="{Binding bingMapsCredentials}" >
<my:MapLayer x:Name="myPushpinLayer">
<my:MapItemsControl Name="Pushpinsss" ItemTemplate="{StaticResource LogoTemplate}" ItemsSource="{Binding PushpinCollection}" >
</my:MapItemsControl>
</my:MapLayer>
</my:Map>
You need to add the MapItemsControl section under your MapLayer
Related
Am developing a simple app for learning pivot control in wp7.
can we add images for pivot item instead of text in header(red mark area in bellow image ).
is it possible to add images, please suggest me
my xaml code is:
<Grid x:Name="LayoutRoot" Background="Transparent">
<!--Pivot Control-->
<controls:Pivot Title="MY APPLICATION" Name="mainPivot">
<!--Pivot item one-->
<controls:PivotItem Header="item1">
<Grid>
<Image Source="/SchoolList;component/Gallery/child.jpg"/>
</Grid>
</controls:PivotItem>
<!--Pivot item two-->
<controls:PivotItem Header="item2">
<Grid>
<Image Source="/SchoolList;component/Gallery/class.jpg"/>
</Grid>
</controls:PivotItem>
</controls:Pivot>
</Grid>
thanks in advance
use this tip :
<phone:Pivot>
<phone:Pivot.HeaderTemplate>
<DataTemplate>
<Image Source="{Binding}" /> // important
</DataTemplate>
</phone:Pivot.HeaderTemplate>
</phone:Pivot>
and then set your Pivot Item header as
<phone:PivotItem Header="path-to-image" >
Yes it is. Simply use HeaderTemplate
<Pivot>
<Pivot.HeaderTemplate>
<DataTemplate>
<Image ... />
</DataTemplate>
</Pivot.HeaderTemplate>
</Pivot>
May I also add that while this is generally possible, it is not recommended for the general use. Unless you need pivot functionality for something completely different. It is somewhat non intuitive.
with the Idea of #toni petrina i added images to the HeaderTemplate to the pivot control using data binding. am implemented image gallery in my app using pivot with images in header template gives great look and feel
Xaml code is :
<controls:Pivot Title="Photo Gallery" Name="mainPivot" ItemsSource="{Binding PivotImages}">
<controls:Pivot.HeaderTemplate>
<DataTemplate>
<Image Name="play" Source="{Binding imgSrc}" Height="80" Width="120" Margin="0,10,0,0"/>
</DataTemplate>
</controls:Pivot.HeaderTemplate>
<controls:Pivot.ItemTemplate>
<DataTemplate>
<Grid>
<Image Name="mainImage" Source="{Binding imgSrc}" />
</Grid>
</DataTemplate>
</controls:Pivot.ItemTemplate>
</controls:Pivot>
and i have created a simple class with one string property to save the images source and prepared a List and assigned to the pivot ItemsSource on page loaded event
mainPivot.ItemsSource = items; // items is the list with image sources
I want to display 3 images in a row in an ListBox. I can't use WrapPanel because it will lose virtualization. So I use VirtualizingStackPanel.
In my ListBoxItem template, I have 3 images in a horizontal StackPanel. I want to allow user to click on a single image, but ListBox's default behavior only allows to click a whole ListBoxItem.
How to do that ?
If you don't want selection on the full row, you should switch to an ItemsControl instead of a ListBox.
To allow selection of images on every row set the ItemTemplate of this ItemsControl to a ListBox, binded to a collection of images.
Here is some sample code that should work:
<ItemsControl ItemsSource="{Binding Collection}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<!--THe ItemTemplate is a ListBox of Images-->
<ListBox>
<ListBox.ItemTemplate ItemsSource="{Binding Images}">
<DataTemplate>
<Image Source="{Binding Img}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<!--This is required to have the scroll-->
<ItemsControl.Template>
<ControlTemplate TargetType="ItemsControl">
<Border>
<ScrollViewer>
<ItemsPresenter/>
</ScrollViewer>
</Border>
</ControlTemplate>
</ItemsControl.Template>
</ItemsControl>
I am using the WP7test framework from Expensify
But i have an issue with my listbox.
<controls:PanoramaItem Header="{Binding Labels.MainMenu_Main}">
<ListBox ItemsSource="{Binding MenuItems}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<cmd:EventToCommand Command="{Binding MenuItemSelectedCommand}" PassEventArgsToCommand="True" />
</i:EventTrigger>
</i:Interaction.Triggers>
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</controls:PanoramaItem>
When i try using the Then I press the control "someName"
Failed to set focus to control 'someName'
Do anybody know how i can select/press the control?
If you want to find items individual then you can put an auto: Tag value on each individual list item.
e.g.: You could use a list item template like
<TextBlock Tag="{Binding AutomationTag}" Text="{Title}" />
where AutomationTag resolves to a unique string for each list item like: auto:1, auto:2, etc.
If you want to refer to a control by name, you need to give it a name. e.g.:
<controls:PanoramaItem Header="{Binding Labels.MainMenu_Main}">
<ListBox ItemsSource="{Binding MenuItems}" Name="someName" />
</controls:PanoramaItem>
The ListBox can now be referred to by name.
What is the easiest way to set the font size of the panorama item header once so it can be used for all item headers in my app?
There isn't a way to automatically do it for all headers in your app yet. You'll need to set the style for each one.
Implicit styling is coming in the Mango update and that should allow this to be done then.
Update
Here's what you can do now.
Create a global template style for the FontSzie you want. Something like:
<Application.Resources>
<DataTemplate x:Key="MyItemHeaderTemplate">
<Grid>
<ContentPresenter>
<TextBlock Text="{Binding}" FontSize="20" />
</ContentPresenter>
</Grid>
</DataTemplate>
</Application.Resources>
Then in every PanoramaItem that I wish to have styled this way I set the HeaderTemplate:
<controls:PanoramaItem Header="first" HeaderTemplate="{StaticResource MyItemHeaderTemplate}">
// ...
</controls:PanoramaItem>
This had been a difficult issue for me as well. However I have found a pretty simple solution to take care of this for each head item you wantto resize/fontweight/font...so-on. I have inserted a snippet from a current project I have been working on. Take notice to the xaml portion for controls:PanoramaItem.HeaderTemplate. This is where the templete is modified for the header item. Good Luck!
<!--Panorama item one-->
<controls:PanoramaItem Header="Locations">
<Grid>
<ListBox Height="498" HorizontalAlignment="Left" Margin="2,0,0,0" Name="listBox1" VerticalAlignment="Top" Width="424" />
</Grid>
<controls:PanoramaItem.HeaderTemplate>
<DataTemplate>
<TextBlock Text="{Binding Content, RelativeSource={RelativeSource TemplatedParent}}" FontSize="55" FontFamily="Segoe WP Bold" Foreground="Black" TextAlignment="Left" FontWeight="Normal" FontStyle="Italic" />
</DataTemplate>
</controls:PanoramaItem.HeaderTemplate>
</controls:PanoramaItem>
Maybe you could try putting this in under the <controls:Panorama> :
<controls:Panorama.TitleTemplate>
<DataTemplate>
<TextBlock Text="{Binding Content, RelativeSource={RelativeSource TemplatedParent}}" FontSize="150" Margin="0,20,0,0" FontWeight="Bold" />
</DataTemplate>
</controls:Panorama.TitleTemplate>
Found here: http://www.jstawski.com/archive/2010/10/25/change-windows-phone-7-panoramarsquos-control-title.aspx
You can create your own PanoramaItem Control and use generic.xaml to apply your custom PanoramaItem style.
public class MyPanoramaItem : Microsoft.Phone.Controls.PanoramaItem
{
public MyPanoramaItem()
{
DefaultStyleKey = typeof(MyPanoramaItem);
}
}
Then you create Themes\Generic.xaml
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:YourProjectNamespace">
<Style TargetType="local:MyPanoramaItem">
<!—your custom PanoramaItem style-->
</Style>
</ResourceDictionary>
And then use your custom Panorama like this:
xmlns:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls"
xmlns:local="clr-namespace:YourProjectNamespace"
<Grid x:Name="LayoutRoot" Background="Transparent">
<!--Panorama control-->
<controls:Panorama Title="my application">
<controls:Panorama.Background>
<ImageBrush ImageSource="PanoramaBackground.png"/>
</controls:Panorama.Background>
<!--Panorama item one-->
<local:MyPanoramaItem Header="first item">
</ local:MyPanoramaItem >
</controls:Panorama>
More about generic.xaml and its usage you can find here.
I am porting an iPhone app to WP7 which contains a map with several markers/pushpins that I get from a webservice (location, icon and title).
I have setup the XAML required to display the map as well as some code for the pushpin:
<phone:PhoneApplicationPage.Resources>
<ControlTemplate x:Key="customPushpin" TargetType="my:Pushpin">
<Image Height="39" Source="Resources/Icons/Pushpins/pinGreen.png" Stretch="Fill" Width="32"/>
</ControlTemplate>
</phone:PhoneApplicationPage.Resources>
<Grid x:Name="LayoutRoot" Background="Transparent">
<my:Map Height="Auto" HorizontalAlignment="Stretch" Margin="0" x:Name="Map"
VerticalAlignment="Stretch" Width="Auto" CredentialsProvider="{Binding CredentialsProvider}"
CopyrightVisibility="Collapsed" LogoVisibility="Collapsed" Center="{Binding Mode=TwoWay, Path=Center}"
ZoomBarVisibility="Visible"
ZoomLevel="{Binding Zoom, Mode=TwoWay}">
<my:MapItemsControl ItemsSource="{Binding Pushpins}">
<my:MapItemsControl.ItemTemplate>
<DataTemplate>
<my:Pushpin MouseLeftButtonUp="Pushpin_MouseLeftButtonUp"
Location="{Binding Location}"
Template="{StaticResource customPushpin}">
</my:Pushpin>
</DataTemplate>
</my:MapItemsControl.ItemTemplate>
</my:MapItemsControl>
</my:Map>
</Grid>
I am looking for a way to add some sort of bubble when the user clicks on the pushpin. I have looked a bit into infoboxes/tooltips but since they work on hover, that's not something I can use for the phone (tap/click).
I am guessing there's no similar control in WP7 that creates a bubble - how could I go about creating something similar?
Thanks in advance,
Alex
You could simply put a square Border inside LayoutRoot with Visibility="Collapsed", then when you click your pushpin you update its content and make it visible.
Just make sure to put it after your map control (otherwise it will be rendered behind the map and will consequently be invisible).
The easiest way to achieve this is to Show/Hide the Content of the Pushpin on Tap instead of MouseLeftButtonUp because of some performance considerations.
void pushPin_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
this.border.Visibility = System.Windows.Visibility.Visible;
//stop the event from going to the parent map control
e.Handled = true;
}
private void map_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
this.border.Visibility = System.Windows.Visibility.Collapsed;
}
You could create a custom popup.
A great video that exaplains how to do this is located here.
Other solution is using the ContextMenu from the Silverlight toolkit for Windows Phone!
Just go to the Coding4Fun page on CodePlex and download it ( it contains the toolkit ) and in your XAML inside the PushPin definition add following:
<map:Pushpin x:Name="currentLocation">
<toolkit:ContextMenuService.ContextMenu>
<toolkit:ContextMenu IsZoomEnabled="False">
<toolkit:MenuItem Header="this is menu item 1" Click="MenuItem_Click" />
<toolkit:MenuItem Header="this is menu item 2" Click="MenuItem_Click" />
<toolkit:MenuItem Header="this is menu item 3" Click="MenuItem_Click" />
</toolkit:ContextMenu>
</toolkit:ContextMenuService.ContextMenu></map:Pushpin>
This way, when you tap and hold the pushpin, you'll get the contectmenu!
( good example also found here: example )