Guys i really need your help, i have a map
xmlns:maps="clr-namespace:Microsoft.Phone.Maps.Controls;assembly=Microsoft.Phone.Maps"
xmlns:maptk="clr-namespace:Microsoft.Phone.Maps.Toolkitassembly=Microsoft.Phone.Controls.Toolkit"
<maps:Map Grid.Row="0" Tap="Onm_MapControlTap" Name="m_MapControl
<maptk:MapExtensions.Children>
<maptk:Pushpin x:Name="m_PushPin" Tap="OnPushPinTap">
<maptk:Pushpin.Content>
<StackPanel>
<TextBlock Text=""/>
<Image Source=""/>
</StackPanel>
</maptk:Pushpin.Content>
</maptk:Pushpin>
</maptk:MapExtensions.Children>
</maps:Map>
when i have coordinates from the geowatcher, or when i tap on the map, i wanna add those coordinates to my pushpin.
m_PushPin.GeoCoordinate = m_watcher.Position.Location;
An exception of type 'System.NullReferenceException' occurred for m_PushPin, i cannot understand why this PushPin is null. Can you tell me what i'm doing wrong, and how can i fix this?
This is a known issue with the XAML Parser. Since your PushPin is nested in an Attached Dependency Property (MapExtensions.Children) it won't be part of the same logical tree as the UserControl and as such won't get picked up by FindName in that scope.
Instead, you should manually traverse the visual tree and get the control you need. Luckily, the map control ships with helper methods just for this occasion.
var pushpin = MapExtensions.GetChildren(myMap).OfType<Pushpin>().First(p => p.Name == "m_PushPin");
As an alternative you could use binding to bind some GeoCoordinate to your pushpin.
Related
I have a trouble when try to rotate MapBase. As far as I didn't find a way to rotate content inside map(i mean tiles). I made a rotation transform with map itself and put it in square to emulate a rectangual viewport.
The problem is the map corner flows over corner of square while rotating and what worst it moves over pivot items titles and I don't know how to bring it to the bottom.
Is there any workaround of that? Or may be other way to rotate the map content?
UPDATE
XAML CODE
here is my code
<Grid x:Name="LayoutRoot" Background="Transparent">
<!--Pivot Control-->
<controls:Pivot Title="MY APPLICATION">
<!--Pivot item one-->
<controls:PivotItem Header="first">
<Grid d:LayoutOverrides="Height" Margin="-44,-30,44,30">
<Microsoft_Phone_Controls_Maps:Map Margin="-18,-72,2,76" RenderTransformOrigin="0.5,0.5" UseLayoutRounding="False" d:LayoutRounding="Auto">
<Microsoft_Phone_Controls_Maps:Map.RenderTransform>
<CompositeTransform Rotation="36.01"/>
</Microsoft_Phone_Controls_Maps:Map.RenderTransform>
</Microsoft_Phone_Controls_Maps:Map>
<Rectangle Fill="#FFF4F4F5" Height="54" Margin="-14,-42,0,0" Stroke="Black" VerticalAlignment="Top"/>
</Grid>
</controls:PivotItem>
<!--Pivot item two-->
<controls:PivotItem Header="second">
</controls:PivotItem>
</controls:Pivot>
</Grid>
In the example is on the top of map, but map is on the top of Pivot headers and even application title is on the back of map corner...
And If you Load another page in "Paysage Orientation" when you rotate your phone ? (It's maybe a temporaly solution... ) but you want to reaload your map with good dimension.
It's not a good idea to use a Map Control inside a Pivot if gesture interaction is enabled.
Don’t use Slider, ToggleButton, or Map controls in a Pivot control. Don’t use controls that can pan or scroll inside a Pivot control. For example, if you put a Map control inside a Pivot control it might be difficult to use the Pivot control. The gesture input gets confused. The solution is to navigate to a subpage with controls that require gesture input. You can place a map in a pivot page as long as the map isn’t enabled for gesture interaction. You could overlay a button that would activate the map. Pressing the button would actually navigate to a separate page with just the Map control on it. The user could then press the Back button to go back to the Pivot control.
http://msdn.microsoft.com/en-us/library/windowsphone/design/hh202919%28v=vs.105%29.aspx
I've got a ListBox (dynamically populated via code):
(i can't insert the code, bah)
I need, with a button, to move this listbox vertically. The listbox have a fixed height, and also the items.
Can someone help me?
Per MSDN, it looks like this is a viable answer for you?
ListBox.ScrollIntoView Method
Edit - Comment Summary of Answer: The question here was targetting scrolling itself, not to a particular object. As such, the necessary action was to attain a reference to the ListBox's ScrollViewer. From there, a call needed to be placed to the ScrollViewer's ScrollToVerticalOffset method. As the OP wanted to scroll down a certain amount from the original position, the ScrollViewer's VerticalOffset property was incorporated into the call.
This works. Set the ListBox to not scroll, then add a ScrollViewer around it. Now in your code behind you can set the ScrollViewer to whatever you want.
XAML:
<!--Disable the ListBox scroll and add a ScrollViewer so we have control over the scroll position.-->
<ScrollViewer
Name="scrlvwrListBoxMessages"
VerticalScrollBarVisibility="Auto" >
<ListBox x:Name="lstbxMessages"
ScrollViewer.VerticalScrollBarVisibility="Disabled" >
</ListBox>
</ScrollViewer>
Code:
private void ScrollToBottom()
{
//Scroll to the bottom.
Dispatcher.BeginInvoke(() =>
{
this.scrlvwrListBoxMessages.ScrollToVerticalOffset(double.MaxValue);
});
}
Hi I want to create a looping listbox so that the last item's next item is the very first item and vice versa - creating a listbox that doesn't have a top or a bottom.
I know there is a LoopingSelector in the WP7 toolkit but it doesn't quite do what I want since it fades in/out peripheral items and you have a 'selected' item that is always in the middle.
I looked at the LinkedList collection but it doesn't seem to support looping: "The LinkedList(Of T) class does not support chaining, splitting, cycles, or other features that can leave the list in an inconsistent state."
Does anyone know a solution for what I'm looking for or would I need to develop a hybrid of the current Listbox and the toolkit's LoopingSelector?
Many thanx!
Take a look at Petzold's article on circular lists in MSDN Magazine.
I recently have a same problem as your! I use blend 4 to handle this, making my list reset to certain position at certain time, also adding a copy of a list in front and behind of the original list.
example: my list is: 1-2-3-4-5-6,
I would make it 1-2-3-4-5-6-1-2-3-4-5-6-1-2-3-4-5-6
and it reset to original position every 20sec. For example: if user was on item 4 it would reset the position to item 4 but at the middle list.
I currently have my question asking here you can check out if anything help:
horizontal listbox that could be infinite circle scrolling
Use Scrollviewer contains listbox, put manipulationCompleted event and use ScrolltoVerticalOffset(0) to have it looping scrolling. Maybe my code would help:
<ScrollViewer HorizontalScrollBarVisibility="Auto" Margin="-2,567,-1,0" x:Name="imagesScrollview"
Opacity="1" Grid.Row="1" RenderTransformOrigin="0.5,0.5"
ManipulationCompleted="imagesScrollview_ManipulationCompleted" Height="85" MouseLeftButtonDown="ScrollViewer_MouseLeftButtonDown">
<ScrollViewer.Background>
<ImageBrush ImageSource="/PhoneApp11;component/Images/top_friends_float.png" />
</ScrollViewer.Background>
<ListBox x:Name="listBox" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Disabled" Width="Auto" Height="80" Background="{x:Null}">
<ListBox.ItemTemplate>
<DataTemplate>
and in Manipulation event:
private void imagesScrollview_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
{
ScrollViewer scrollviewer = sender as ScrollViewer;
if (scrollviewer.HorizontalOffset > (listBox.ActualWidth - 700))
scrollviewer.ScrollToHorizontalOffset(0);
else if (scrollviewer.HorizontalOffset < 100)
scrollviewer.ScrollToHorizontalOffset((listBox.ActualWidth - 487));
}
***Notice: I allow my scrollviewer to loop in both way.
I want to program an application based on wpf c# language.
I've got the bing map running and i want the dataset to display on the map with pushpin on top of the specific locations.
I don't know if you could make it work but i could do this whit this few lines of XAML code and Binding.
<bing:MapItemsControl ItemsSource="{Binding LocationsList}">
<bing:MapItemsControl.ItemTemplate>
<DataTemplate>
<bing:Pushpin Location="{Binding Location}" Content="{Binding Content}">
</bing:Pushpin>
</DataTemplate>
</bing:MapItemsControl.ItemTemplate>
</bing:MapItemsControl>
How can I draw on bing maps? Or actually I'd like to add a marker. I have detected coordinates and now I want to display this place on a map with a marker...
To draw lines on a map you use the MapPolyline element as a child of the Map control. To add a marker to the Map control, you add a Pushpin element as a child of the Map control. To add multiple items (lines or pushpins) you add a MapItemsControl as a child of the Map control and specify the ItemsSource and ItemTemplate.
The following code example shows a PushPin to display the current location, and a MapItemsControl to show waypoints on a route:
<maps:Map x:Name="_map"
CopyrightVisibility="Collapsed"
CredentialsProvider="Your API Key Here"
LogoVisibility="Collapsed">
<maps:MapItemsControl ItemsSource="{Binding WayPoints}">
<maps:MapItemsControl.ItemTemplate>
<DataTemplate>
<maps:Pushpin Background="{Binding BackgroundBrush}" Location="{Binding Location}"/>
</DataTemplate>
</maps:MapItemsControl.ItemTemplate>
</maps:MapItemsControl>
<maps:Pushpin x:Name="_current" Background="Blue" Location="{Binding CurrentLocation}"/>
</maps:Map>
This blog post may also help you get started.