Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
lawrence_shaun_introducing_net_maui_build_and_deploy_crosspl.pdf
Скачиваний:
46
Добавлен:
26.06.2023
Размер:
5.15 Mб
Скачать

Chapter 11 Getting Specific

You have introduced a few changes here so let’s break them down. First, you are calling the locationService to get the device’s location.

If it returns null, it means the application does not have permission and you set the State to PermissionError.

If you have permission, you pass the device’s current location into the weatherForecastService.GetForecast method.

Displaying Permission Errors to Your User

You have added the new state value and also assigned it in your view model when you either fail to retrieve the permission setting or the user has denied permission to the LocationWhenInUse feature. Now you can add in support into your UI to respond to this value and show something appropriate to the user. Open the WeatherWidgetView.xaml file and make the following modifications.

Add in the converter instance inside the <ContentView.Resources> tag.

<converters:IsEqualToStateConverter

x:Key="HasPermissionErrorConverter" State="PermissionError" />

Then you can add a section that will render when the State property is equal to PermissionError. You should add this into the WeatherWidgetView.xaml file after the following section:

<!-- Error --> <VerticalStackLayout

IsVisible="{Binding State, Converter={StaticResource HasErrorConverter}}">

...

</VerticalStackLayout>

345