Quick Tip #3 – Checking for Internet Connectivity

How do we get to know whether the app has internet connectivity? This is important when you want to check for connectivity before doing a server sync.

 public static bool IsInternetAvailable
     var profiles = NetworkInformation.GetConnectionProfiles();
     var internetProfile = NetworkInformation.GetInternetConnectionProfile();
     return profiles.Any(s => s.GetNetworkConnectivityLevel() == NetworkConnectivityLevel.InternetAccess) || (internetProfile != null && internetProfile.GetNetworkConnectivityLevel() == NetworkConnectivityLevel.InternetAccess);

May the code be with you! 😀




Quick Tip #2 – Stretching the ItemContainter of ListView

Suppose you have a data template for a Listview. It so happens that the Grid does not fill the whole list view. Your content seems to be left aligned.

Solution: You  need to set the ItemContainerStyle for the ListView

<ListView x:Name="InviteLV" ItemsSource="{Binding}" HorizontalContentAlignment="Stretch">
<Grid MinHeight="60" HorizontalAlignment="Stretch" >
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
<StackPanel HorizontalAlignment="Stretch" Margin="10,0,20,0">
<TextBlock Text="{Binding InviteName}" Foreground="Black" FontSize="26"/>
<TextBlock Text="{Binding InviteEmail}" Foreground="Black" FontSize="26"/>
<Button Grid.Column="1" BorderThickness="0" Width="50" Height="50" Margin="0">
<ImageBrush Stretch="Fill" ImageSource="Assets/Images/theme1_but_cancel_normal.png"/>

<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>