Silverlight中常用知識總結

來源:互聯網
上載者:User
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;            }        }...

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.