public class NetworkState : INotifyPropertyChanged
{
public NetworkState()
{
NetworkChange.NetworkAddressChanged +=
(sender, args) => SendNotifyPropertyChanged("IsOnline");
}
public void SendNotifyPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
public bool IsOnline
{
get
{
return NetworkInterface.GetIsNetworkAvailable(); ;
}
}
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
#endregion
}
<UserControl x:Class="SilverlightNetworkState.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:SilverlightNetworkState"
Width="400" Height="300">
<UserControl.Resources>
<local:NetworkState x:Key="State" />
</UserControl.Resources>
<Grid x:Name="LayoutRoot" Background="White">
<CheckBox Margin="10" IsChecked="{Binding Path=IsOnline, Source={StaticResource State}}" Content="Online" />
</Grid>
</UserControl>