public abstract class NotificationObject : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; protected virtual void RaisePropertyChanged(string propertyName) { PropertyChangedEventHandler handler = this.PropertyChanged; if (handler != null) { handler(this,new PropertyChangedEventArgs(propertyName)); } } protected void RaisePropertyChanged(params string[] propertyNames) { if (propertyNames == null) throw new ArgumentNullException("propertyNames"); foreach (var name in propertyNames) { this.RaisePropertyChanged(name); } } protected void RaisePropertyChanged<T>(Expression<Func<T>> propertyExpression) { var propertyName = ExtractPropertyName(propertyExpression); this.RaisePropertyChanged(propertyName); } public static string ExtractPropertyName<T>(Expression<Func<T>> propertyExpression) { if (propertyExpression == null) { throw new ArgumentNullException("propertyExpression"); } var memberExpression = propertyExpression.Body as MemberExpression; if (memberExpression == null) { throw new ArgumentException("PropertySupport_NotMemberAccessExpression_Exception","propertyExpression"); } var property = memberExpression.Member as PropertyInfo; if (property == null) { throw new ArgumentException("PropertySupport_ExpressionNotProperty_Exception","propertyExpression"); } var getmethod = property.Getgetmethod(true); if (getmethod.Isstatic) { throw new ArgumentException("PropertySupport_StaticExpression_Exception","propertyExpression"); } return memberExpression.Member.Name; } } 相应的,Student类型为: public class Student : NotificationObject { string firstName; public string FirstName { get { return firstName; } set { firstName = value; //Notify("FirstName"); this.RaisePropertyChanged("FirstName"); } } string lastName; public string LastName { get { return lastName; } set { lastName = value; //Notify("LastName"); this.RaisePropertyChanged("LastName"); } } public Student(string firstName,string lastName) { this.firstName = firstName; this.lastName = lastName; } }
Windows Phone7获取当前网络状态
using Microsoft.Phone.Net.networkinformation; ... string netState,netName; private bool _networkIsAvailable; private NetworkInterfaceType _currentNetworkType; //网络连接的类型 private void GetNetInfo(object sender,RoutedEventArgs e) { _networkIsAvailable = NetworkInterface.GetIsNetworkAvailable();//当前网络是否可用 _currentNetworkType = NetworkInterface.NetworkInterfaceType;//获取当前网络的类型 if (_networkIsAvailable) { netState = "联网状态"; //Message.Background = new SolidColorBrush(Colors.Green); } else { netState = "断网状态"; //Message.Background = new SolidColorBrush(Colors.Red); } switch (_currentNetworkType) { case NetworkInterfaceType.MobilebroadbandCdma: netName = "CDMA网络"; break; case NetworkInterfaceType.MobilebroadbandGsm: netName = "CSM网络"; break; case NetworkInterfaceType.Wireless80211: netName = "Wi-Fi网络"; break; case NetworkInterfaceType.Ethernet: netName = "Ethernet网络"; break; case NetworkInterfaceType.None: netName = "网络不可用"; break; default: netName = "其他的网络"; break; } } ...
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。