第二十八章 如何在 Silverlight 页面上弹出层?

 

xaml页面上添加一个按钮,如下所示:

< Grid x : Name ="LayoutRoot" Background ="White" >

    <ButtonWidth ="100" Height ="50" x : Name ="showPopup" Click ="showPopup_Click"

         Content ="Show Popup" />

</ Grid >

在后置代码文件(page.xaml.cs)中添加如下代码

Popup p = new Popup ();

private void showPopup_Click(object sender,RoutedEventArgs e) {

    // Create a panel control to host other controls

    StackPanel panel1 = new StackPanel ();

    panel1.Background = new SolidColorBrush (Colors .Gray);

 

    // Create a button

    Button button1 = new Button ();

    button1.Content = "Close" ;

    button1.Margin = new Thickness (5.0);

    button1.Click += new RoutedEventHandler (button1_Click);

 

    // Create a text label

    TextBlock textblock1 = new TextBlock ();

    textblock1.Text = "The popup control" ;

    textblock1.Margin = new Thickness (5.0);

 

    // Add text label and button to the panel

    panel1.Children.Add(textblock1);

    panel1.Children.Add(button1);

 

    // Now, make the panel a child of the popup so that

    // the panel will be shown within the Popup when displayed.

    p.Child = panel1;

 

    // Set the position.

    p.VerticalOffset = 25;

    p.HorizontalOffset = 25;

 

    // Show the popup.

    p.IsOpen = true ;

}

 

void button1_Click(object sender, RoutedEventArgs e) {

    // Close the popup.

    p.IsOpen = false ;

}

注意:需要添加System.Windows.Controls.Primitives命名控件的引用。

运行应用程序。可以看见页面上有一个按钮。当点击按钮时,一个具有文本标签和按钮的弹出层会显示。当点击弹出层中按钮,将会关闭弹出层。

 

Silverlight入门知识学习目录

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值