Windows Phone 7 开发小技巧
1.使用Popup来实现自定义的弹出效果。Popup控件弹出的块会一直在屏幕的最前方,所以使用Popup可以实现各种各样的弹出框,并且给了你极大的自定义的空间,很多第三方的弹出框控件的原理其实就是使用了Popup来包装上各种效果来实现的。Popup使用的方法:
private Popup popup;
popup = new Popup();
popup.Child = new 控件类();
//打开
popup.IsOpen = true;
//关闭
popup.IsOpen = false
或者
xaml代码
……
cs代码
//打开
popup.IsOpen = true;
//关闭
popup.IsOpen = false
2.在TextBlock控件中使用进行换行。
测试
测试
测试
3.捕获物理按键返回键,打开页面,离开页面。windows phone有3个物理按键,返回键,开始键,搜索键,后面两个无法在程序中捕获到。
//点击返回按钮
protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
{
//你的代码
e.Cancel = false;
base.OnBackKeyPress(e);
}
//从其他页面进入该页面
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
//你的代码
base.OnNavigatedTo(e);
}
//离开当前的页面
protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
{
//你的代码
base.OnNavigatedFrom(e);
}
4.获取父控件里面的子控件的方法。之前在判断ListBox控件什么时候滚到底的时候使用过该方法,这个方法很常用。
//获取第一个子类型
public static T FindChildOfType(DependencyObject root) where T : class
{
var queue = new Queue();
queue.Enqueue(root);
while (queue.Count > 0)
{
DependencyObject current = queue.Dequeue();
for (int i = VisualTreeHelper.GetChildrenCount(current) - 1; 00)
{
DependencyObject current = queue.Dequeue();
for (int i = VisualTreeHelper.GetChildrenCount(current) - 1; 0
页:
[1]