Silverlight中常用知識總結
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;
}
}
...
相關文章
- Silverlight 常用小知識點總結
- RabbitMQ 常用知識點總結MQ
- # Redis 常用知識總結(一)Redis
- MSSQL Server常用知識總結SQLServer
- docker常用知識點總結Docker
- mysql 常用知識點總結MySql
- 作業系統常用知識總結!作業系統
- 專案中常用jquery知識總結jQuery
- MySQL 常用易混淆知識點總結MySql
- Android開發常用知識總結Android
- .NET開發常用知識點總結匯總
- ES6常用知識點總結(上)
- ES6常用知識點總結(下)
- c語言常用小知識點總結1C語言
- jQuery常用的一些知識點總結jQuery
- 面試開發常用的 JavaScript 知識點總結面試JavaScript
- Vue知識精簡總結-更新中Vue
- MySQL基礎知識和常用命令總結MySql
- linux知識知識點總結Linux
- Redis知識總結Redis
- Cookie知識總結(-)Cookie
- 圖知識總結
- golang知識總結Golang
- servlet知識總結Servlet
- 常量知識總結
- Docker知識總結Docker
- JQuery知識總結jQuery
- servelt知識總結
- 知識點總結
- SWAP知識總結
- MySQL知識總結MySql
- PayPal知識總結
- 小知識總結
- 知識方法總結
- Java中IO流的知識點總結Java
- ES6 常用知識彙總
- iOS 知識-常用小技巧彙總iOS
- HDFS知識點總結