in my app for WP7(mango) I need to navigate the user from one point to another. I know there is the Map control that lets you draw staff on it, but how do you ask it to draw the path for you? (based on the specified destination & user's current location - but that keeps changing so how do you update the route if he goes of the way?)
To update the map with the users current location, use the GeoCoordinateWatcher and update the position of a databound Pushpin as it changes. Remember to set the minimum distance to something low, like 5 meters.
A pushpin like the one on bing maps, can be created with this XAML template:
<maps:Pushpin Background="{StaticResource PushpinLocationBrush}"
Location="{Binding MyLocation}">
<maps:Pushpin.Template>
<ControlTemplate>
<Grid>
<Rectangle Width="15"
Height="15"
Margin="0"
Fill="Black">
<Rectangle.Projection>
<PlaneProjection CenterOfRotationX="0"
LocalOffsetX="-2"
LocalOffsetY="5"
RotationZ="45" />
</Rectangle.Projection>
</Rectangle>
<Ellipse Width="7"
Height="7"
Margin="0"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Fill="Orange"
RenderTransformOrigin="0.339,0.232"
StrokeThickness="0" />
</Grid>
</ControlTemplate>
</maps:Pushpin.Template>
</maps:Pushpin>
Getting the GeoCoordinate of a address can be done with Bing Maps. You can read more about Bing Services here: http://msdn.microsoft.com/en-us/library/cc980922.aspx -- the one you need is the GeoCodeService
Drawing a path is rather complicated, specially if you want it to follow the roads. For this, you need the Bing Maps Route Service.
Add the service to Visual Studio, with RouteServiceReference as name, and then you can utilize following code to get the path fragments, and add them to your map. The XAML below reflects the controls I add the fragments to:
List<GeoCoordinate> locations = new List<GeoCoordinate>();
RouteServiceClient routeService = new RouteServiceClient("BasicHttpBinding_IRouteService");
routeService.CalculateRouteCompleted += (sender, e) =>
{
var points = e.Result.Result.RoutePath.Points;
var coordinates = points.Select(x => new GeoCoordinate(x.Latitude, x.Longitude));
var routeColor = Colors.Blue;
var routeBrush = new SolidColorBrush(routeColor);
var routeLine = new MapPolyline()
{
Locations = new LocationCollection(),
Stroke = routeBrush,
Opacity = 0.65,
StrokeThickness = 5.0,
};
foreach (var location in points)
{
routeLine.Locations.Add(new GeoCoordinate(location.Latitude, location.Longitude));
}
RouteLayer.Children.Add(routeLine);
};
RouteBingMap.SetView(LocationRect.CreateLocationRect(locations));
routeService.CalculateRouteAsync(new RouteRequest()
{
Credentials = new Credentials()
{
ApplicationId = "YOURBINGMAPSKEYHERE"
},
Options = new RouteOptions()
{
RoutePathType = RoutePathType.Points
},
Waypoints = new ObservableCollection<Waypoint>(
locations.Select(x => new Waypoint()
{
Location = x.Location
}))
});
Related XAML:
<maps:Map x:Name="RouteBingMap"
AnimationLevel="None"
CopyrightVisibility="Collapsed"
CredentialsProvider="YOURBINGMAPSKEYHERE"
LogoVisibility="Collapsed"
ZoomBarVisibility="Collapsed"
ZoomLevel="12">
<maps:MapLayer x:Name="RouteLayer" />
</maps:Map>
Related
I have a implement syncfusion Carousel and binding items using ItemTemplate.When i load the items to Carousel all item appears in Carousel view.But i need to add a doted indicator for it.
When user swipe though the Carousel by the dots should indicate current position.
When reading from documentation of syncfusion rotator have this functionality.
I need to add this to carousel view.
Here you can find all the SfCarousel Class Members.
And there's no property for the dots you refered in the SfCarousel print.
In fact, I think you are confusing it with another component called SfRotator. (that has an identical example like your print). and the property you are looking for is called: DotPlacement.
And can have the following states:
None //No Dots
Default //Dots Inside the Rotator View
OutSide //Dots Outside the Rotator View
We have analyzed your query and currently we don’t have dots view support in CarouselView. However, we can fulfill this requirement by using Border or Button control as like below code snippet.
Custom DotsView:
XAML:
<border:SfBorder BorderColor="{Binding ThumbBorder}" HorizontalOptions="Center" VerticalOptions="Center" BorderWidth="5" CornerRadius="50" />
Carousel View:
XAML:
<carousel:SfCarousel x:Name="carousel" Grid.Row="0" Offset="0" ItemsSource="{Binding ImageCollection}" ItemTemplate="{StaticResource itemTemplate}"
ItemHeight="200" SelectionChanged="Carousel_SelectionChanged"
ItemWidth="200" />
<StackLayout Grid.Row="1" HorizontalOptions="Center" x:Name="rotatorThumb" BackgroundColor="Transparent" Orientation="Horizontal"/>
C#:
public MainPage()
{
InitializeComponent();
Command command = new Command((object thumb) =>
{
var thumbView = thumb as DotsView;
if (thumbView != null)
{
((rotatorThumb.Children[carousel.SelectedIndex] as DotsView).BindingContext as CarouselModel).
ThumbBorder = Color.LightGray;
carousel.SelectedIndex = thumbView.Index;
(thumbView.BindingContext as CarouselModel).ThumbBorder = Color.Red;
}
});
for (var i = 0; i < ImageCollection.Count; i++)
{
var itemView = new DotsView() { BindingContext = ImageCollection[i], Index = i };
if (carousel.SelectedIndex == i)
(itemView.BindingContext as CarouselModel).ThumbBorder = Color.Red;
TapGestureRecognizer thumbTap = new TapGestureRecognizer();
thumbTap.Command = command;
itemView.GestureRecognizers.Add(thumbTap);
thumbTap.CommandParameter = itemView;
rotatorThumb.Children.Add(itemView);
}
}
Output:
Sample
I have MapItemsControl, Pushpins and Data-binding:
<toolkit:MapItemsControl>
<toolkit:MapItemsControl.ItemTemplate>
<DataTemplate>
<toolkit:Pushpin GeoCoordinate="{Binding Coordinate}"
Content="{Binding ContentPushpin}"
Background="{Binding Background}"
Tag="{Binding Tag}"
Tap="userPushpin_Tap"
>
</toolkit:Pushpin>
</DataTemplate>
</toolkit:MapItemsControl.ItemTemplate>
</toolkit:MapItemsControl>
Binding pushpins to MapItemsControl:
ObservableCollection<MyPushpin> PushpinsCollections = ObservableCollection<MyPushpin>();
PushpinsCollections.Add(new MyPushpin()
{
Coordinate = ....,
Id = ...
//init other properties
});
NokiaMapItemsControl.ItemsSource = PushpinsCollections;
Next, one of the Pushpin changed the coordinates, I can find it in the collection by a unique ID. But how can I change his position that these changes appear on the map, without redrawing the other pushpins?
I have a pivot control with non data bound pivot items which have different kind of structure. all of them have simple text headers. How can we change the visibility of the headers
based on orientation changes? what I want to achieve is, when the phone is in landscape i want
the headers to be invisible and all the space to be utilized by the the respective contents inside the pivot items. I tried a lot, and the biggest problem is the panel that carries the headers is always taking the original height.(I tried to change font size, visibility etc...)
Please help. Here is my code sample
<controls:Pivot x:Name="pvtMain" >
<controls:PivotItem x:Name="pvtItemOne" Header="My Header one">
<MyUserControls:UserControlOne/>
</controls:PivotItem>
<controls:PivotItem x:Name="pvtItemTwo" Header="My Header Two">
<MyUserControls:UserControlTwo/>
</controls:PivotItem>
<controls:PivotItem x:Name="pvtItemThree" Header="My Header Three">
<MyUserControls:UserControlThree/>
</controls:PivotItem>
</controls:PivotItem>
I am using Windows phone SDK 7.0 (for backwards compatibility reason)
This may work. Give it a try!!
void MainPage_OrientationChanged(object sender, OrientationChangedEventArgs e)
{
if (e.Orientation == PageOrientation.Landscape || e.Orientation == PageOrientation.LandscapeLeft || e.Orientation == PageOrientation.LandscapeRight)
{
pvtItemOne.Header = null;
pvtItemTwo.Header = null;
pvtItemThree.Header = null;
pvtMain.Margin = new Thickness(0, -150, 0, 0);
}
else
{
pvtItemOne.Header = "My Header One";
pvtItemTwo.Header = "My Header Two";
pvtItemThree.Header = "My Header Three";
pvtMain.Margin = new Thickness(0);
}
}
By the way, you don't need to maintain any backward compatibility for 7.0 devices. Microsoft stopped support for those devices long back and Marketplace is closed for those.
You can do the following :
<controls:PivotItem >
<controls:PivotItem.Header>
<Border x:Name="PivotItemHeader">
<TextBlock Text="Test" />
</Border>
</controls:PivotItem.Header>
<StackPanel>
<TextBlock Text="line1" />
<TextBlock Text="line2" />
</StackPanel>
</controls:PivotItem>
By using the "border" inside the Header you can control its visibility from code.
like : PivotItemHeader.Visibility = System.Windows.Visibility.Collapsed ;
I know it is not pretty but it works.
I'm trying to find a method of displaying a text block or that will allow me to arbitrarily drag and drop drop that control around the screen.
I've scoured google and here, but every drag and drop related question I find is around exchanging data, not just position.
Is anyone aware of something ready to go, or can you point me in the direction I should be looking?
You can do this by using behaviors:
<TextBlock Text="Hello!">
<i:Interaction.Behaviors>
<el:MouseDragElementBehavior ConstrainToParentBounds="True"/>
</i:Interaction.Behaviors>
</TextBlock>
You need to add a reference to Microsoft.Expression.Interactions in your solution, and the following namespace at the top of your XAML file:
xmlns:el="clr-namespace:Microsoft.Expression.Interactivity.Layout;assembly=Microsoft.Expression.Interactions"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
The xaml:
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<TextBlock Height="30" Margin="125,132,0,0"
Name="textBlock1" Text="TextBlock"
Width="83" MouseMove="textBlock1_MouseMove" />
</Grid>
and the code behind:
private void textBlock1_MouseMove(object sender, MouseEventArgs e)
{
TextBlock realSender = (TextBlock)sender;
var theParent = (Grid)realSender.Parent;
var position = e.GetPosition(theParent);
realSender.Margin = new Thickness(
position.X - realSender.Width / 2,
position.Y - realSender.Height / 2, 0, 0);
}
The toolkit sample used to include an example of doing this.
Not sure if it's still in there though as it was based on the gesture support which has since been deprecated. If it's gone check the August 2011 version.
I've failed certification because I have an image that's all white. So when a user switches to the light theme it fails because you can't see it. How do I swap this imaged based on the theme applied?
Thank you in advance
Question Making an image control invert its colors depending on theme has a simple XAML only answer:
<Image HorizontalAlignment="Center"Stretch="None" Visibility="{StaticResource PhoneLightThemeVisibility}" Source="/MyApplication;component/imageDarkTheme.png" />
<Image HorizontalAlignment="Center" Stretch="None" Visibility="{StaticResource PhoneDarkThemeVisibility}"Source="/MyApplication;component/imageLightTheme.png" />
In XAML
<Image Source="{Binding ImageSource}" />
In the view model that contains property ImageSource
public string ImageSource
{
get
{
if( (Visibility)App.Current.Resources["PhoneDarkThemeVisibility"]
== Visibility.Visible ) {
return "/path/to/dark/image.png";
} else {
return "/path/to/light/image.png";
}
}
private set {}
}
This may not change the picture if the user tombstones your app, changes the theme and switches back to the app.
One way to handle that scenario is to cache the current theme setting in the App class constructor, then compare it with the current setting within App.Application_Activated, if they're different you'll need to somehow indicate that the above view model needs to fire a property changed notification for ImageSource.
For anyone following my comments above - I had to switch from ImageBrush to Image directly (xaml below)
<Button Tag="{Binding}" VerticalAlignment="Center" HorizontalAlignment="Right" Margin="-10,20,0,0" BorderThickness="0" Width="105" Height="102" Click="ShowKioskOnMap_Click">
<Image Source="../images/arrow.png" Width="55" Height="53" ImageOpened="Image_ImageOpened"/>
</Button>
Next in the consructor of the page I'm using --I did the theme lookup to prevent any issues when the app state is restored from taking a phone call for instance (or just loading up the view for the first time)
InitializeComponent();
theme = ""; //field level var (could make it dark by default if needed)
if ((Visibility)App.Current.Resources["PhoneDarkThemeVisibility"] == Visibility.Visible)
{
theme = "dark";
}
else
{
theme = "light";
}
And I had to implement the following in my open event to switch based on theme
private void Image_ImageOpened(object sender, RoutedEventArgs e)
{
var brush = (sender as Image);
if (brush.Stretch == Stretch.Uniform)
{
if (theme == "light")
brush.Source = new BitmapImage(new Uri("../images/arrowLight.png", UriKind.Relative));
brush.Stretch = Stretch.Fill;
}
}