Silverlight 之模态对话框的通用模拟
2008-10-24 11:46:53 来源:WEB开发网这里照搬了 ScottGu 文章中的那个技巧,不过我改成了用一个 Border 元素来占位,同时将它的大小设置为全屏、半透明、不可见状态。这样它就既可以作为子窗体的容器,又可以在弹出模态对话框时遮住背景,一举两得。
后端代码 Page.xaml.cs:
using System.Windows;
using System.Windows.Controls;
namespace ModalPopupDemo
{
publicpartialclass Page : UserControl, IModalDialogOpener
{
public Page()
{
InitializeComponent();
}
privatevoid btnOpen_Click(object sender, RoutedEventArgs e)
{
var login =new Login();
login.Closed += (sender2, args2) => CloseModalDialog();
ShowModalDialog(login);
}
privatevoid btnOpen2_Click(object sender, RoutedEventArgs e)
{
var form2 =new Form2();
form2.Closed += (sender2, args2) => CloseModalDialog();
ShowModalDialog(form2);
}
#region IModalDialogOpener implementations
publicvoid ShowModalDialog(ModalDialog dialog)
{
placeHolder.Child = dialog;
placeHolder.Visibility = Visibility.Visible;
}
publicvoid CloseModalDialog()
{
placeHolder.Child =null;
placeHolder.Visibility = Visibility.Collapsed;
}
#endregion
}
}
Tags:Silverlight 模态 对话框
编辑录入:爽爽 [复制链接] [打 印]- ››Silverlight for Windows Phone 7开发系列(1):...
- ››Silverlight for Windows Phone 7开发系列(2):...
- ››Silverlight for Windows Phone 7开发系列(3):...
- ››Silverlight for Windows Phone 7开发系列(4):...
- ››Silverlight for Symbian
- ››对话框模板RegexTest
- ››对话框打印预览及打印
- ››Silverlight3系列(四)数据绑定 Data Binding 1
- ››silverlight2 游戏 1 你能坚持多少秒
- ››Silverlight开发实践--PicZoomShow
- ››Silverlight自定义控件开发 - 令人懊恼的OnApplyT...
- ››Silverlight 2 RTW中ToolTipService.ToolTip不继承...
更多精彩
赞助商链接