Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Phone_81_Development_for_Absolute_Beginners

.pdf
Скачиваний:
34
Добавлен:
10.02.2015
Размер:
18.77 Mб
Скачать

<Button Name="CompletedButton" Content="I Did this Today!"

Command="{Binding CompletedCommand}" CommandParameter="{Binding}"

IsEnabled="{Binding Dates, Converter={StaticResource IsCompleteToBooleanConverter}}" />

The key here is the IsEnabled property which is bound to the Dates collection, but converted using our new Value Converter.

The final feature we’ll add is the progress bar. We want to add a ProgressBar below the button. We’ll hard wire the Value attribute to 1, but we’ll work on a Value Converter that will bind the Value to a count of Dates for a given Ritual which will allow us to see the progress against our Goal:

In the ValueConverter folder, we’ll Add a new Item. In the Add New Item dialog, we’ll add (1) a new Class (2) named CompletedDatesToIntegerConverter.cs and (3) click the Add button:

Windows Phone 8.1 Development for Absolute Beginners – Page 300

We’ll use the techniques described earlier to implement the IValueConverter interface:

Windows Phone 8.1 Development for Absolute Beginners – Page 301

In the Convert() method, we’ll expect the value to be passed in as an ObservableCollection<Date>. Then, we’ll simply return the number of items in that collection:

Once we’ve implemented our converter, we’ll add a new reference to it in the Page.Resources section of MainPage:

Windows Phone 8.1 Development for Absolute Beginners – Page 302

Then we’ll change the Value attribute to bind to the Dates collection converting it to an integer (the count of dates) using our new CompletedDatesToIntegerConverter:

Now when we run the app and click the “I Did This Today” button, we can see the button becomes disabled and the ProgressBar creeps up 1/30th of it’s width:

There are still some small improvements we could make to the layout and branding of the app, but we tackled the most challenging aspects from beginning to end. The great thing about this example is that we used many different pieces to we’ve learned about in previous lessons and you can see how they contributed to the overall functionality we desired.

Windows Phone 8.1 Development for Absolute Beginners – Page 303

Lesson 27: Working with the Map Control and the Geolocation and GeoPosition Classes

In this lesson, we're going to talk about the map control and talk about the GPS sensor inside of the device. Besides the specifics of the GPS sensor, the more general principles of working with the Phone’s sensors apply here as well. So, while we are examining a specific capability, you can apply the general knowledge to all the capabilities of the Phone and how to work with them. The Phone’s API always supplies classes and methods representing the particular sensor and its functionality you want to work with. In the case of the Phone’s location features, we'll be able to get the latitude and the longitude in a GeoPosition object that we can then work with. What can we do with the location, the GeoPosition object? For one thing, it works well with the Map Control. We can set current position of the Map Control to a specific location (GeoPosition) or retrieve the current location from the Map control and ask "Where in the world are you displaying?" We can zoom into the map, zoom out of the map, and things of that nature.

We’ll start by opening the New Project dialog (1) creating a new Blank App project, (2) renaming it to LocationAndMaps, and (3) clicking the OK button.

Windows Phone 8.1 Development for Absolute Beginners – Page 304

The easiest way to get started working with the Map Control is to use the Toolbox. Usually, I advocate directly typing in the XAML, however as we’ll see in a moment, the Map Control requires a bit of extra work that the drag-and-drop action will take care of for us:

Here I resize the Map Control on the design surface so that we can see the message that it only renders when the app is running:

Windows Phone 8.1 Development for Absolute Beginners – Page 305

In addition to the XAML that was generated inside of the Grid, notice the namespace that was added to the Page’s namespace declarations:

This is one reason why I prefer to drag-and-drop to the design surface when working with the MapControl.

Next, I’ll edit the layout of the Grid and the Map. Ideally, it takes up the first row set to

*:

Windows Phone 8.1 Development for Absolute Beginners – Page 306

And when I run the app, notice that the Map is simply set to North America (at least, since I am in North America. I’m not sure what would happen if you tried this from other parts of the world).

Windows Phone 8.1 Development for Absolute Beginners – Page 307

The first thing I want to accomplish is the set the MapControl, by default, to a specific location. I’ll choose an out door mall near the Microsoft campus in Redmond, Washington, as the location of the Phone using the Emulator’s Additional Tools dialog:

Windows Phone 8.1 Development for Absolute Beginners – Page 308

Back in my project, in the MainPage.xaml.cs I’ll modify the OnNavigatedTo() event handler method to work with the Geolocator. This object is your interface to the GPS / location features of the Phone. Since we’re running in emulation, I would expect to retrieve the location in Redmond, Washington that I set. Once I have the Geolocator retrieving the location, I attempt to set the MapControl’s view to that location:

Windows Phone 8.1 Development for Absolute Beginners – Page 309

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]