none
有没有关于popup的samplecode? RRS feed

  • 问题

  • 我看了下提供的sample里面好像没有关于popup的sample只有关于messagedialog的

    我自己尝试了下popup,但是遇到一些问题:

    1,在有些页面popup显示得出来,有些页面就显示不出来(必须指定在某个grid的row里面才能显示)

    2,怎样让这个popup自适应屏幕宽度,而不是设定width=333

    3,怎样让popup之外的部分暗下去而且无法点击

    想实现的效果就如下

    2012年6月6日 6:58

答案

  • 这样一个例子代码应该可以理解了:

            public MainPage()
            {
                this.InitializeComponent();
                this.SizeChanged += MainPage_SizeChanged;
                this.Loaded += (o, e) =>
                {
                    messagePopup.Width = this.ActualWidth;
                    Grid grid = new Grid()
                    {
                        Width = this.ActualWidth,
                        Background = new SolidColorBrush(Colors.PaleGreen)
                    };
                    Button okbtn = new Button()
                    {
                        Content = "OK",
                        HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Right,
                        VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Bottom
                    };
                    okbtn.Click += okbtn_Click;
                    grid.Children.Add(okbtn);
                    messagePopup.Child = grid;
                };
            }
    
            void MainPage_SizeChanged(object sender, SizeChangedEventArgs e)
            {
                messagePopup.Width = this.ActualWidth;
            }
    
            /// <summary>
            /// Invoked when this page is about to be displayed in a Frame.
            /// </summary>
            /// <param name="e">Event data that describes how this page was reached.  The Parameter
            /// property is typically used to configure the page.</param>
            protected override void OnNavigatedTo(NavigationEventArgs e)
            {
            }
    
            void okbtn_Click(object sender, RoutedEventArgs e)
            {
                if (messagePopup.IsOpen)
                    messagePopup.IsOpen = false;
                this.IsEnabled = true;
            }
    
            Popup messagePopup = new Popup();
            private void Button_Click_1(object sender, RoutedEventArgs e)
            {
                this.IsEnabled = false;
                messagePopup.VerticalOffset = (this.ActualHeight - messagePopup.ActualHeight) / 2;
                messagePopup.IsOpen = true;
            }


    Bob Bao [MSFT]
    MSDN Community Support | Feedback to us

    2012年6月11日 11:02
    版主

全部回复

  • JS还是XAML?  他们实现是不同的。

    Bob Bao [MSFT]
    MSDN Community Support | Feedback to us

    2012年6月7日 2:37
    版主
  • JS还是XAML?  他们实现是不同的。

    Bob Bao [MSFT]
    MSDN Community Support | Feedback to us

    XAML
    2012年6月8日 8:33
  • 这样一个例子代码应该可以理解了:

            public MainPage()
            {
                this.InitializeComponent();
                this.SizeChanged += MainPage_SizeChanged;
                this.Loaded += (o, e) =>
                {
                    messagePopup.Width = this.ActualWidth;
                    Grid grid = new Grid()
                    {
                        Width = this.ActualWidth,
                        Background = new SolidColorBrush(Colors.PaleGreen)
                    };
                    Button okbtn = new Button()
                    {
                        Content = "OK",
                        HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Right,
                        VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Bottom
                    };
                    okbtn.Click += okbtn_Click;
                    grid.Children.Add(okbtn);
                    messagePopup.Child = grid;
                };
            }
    
            void MainPage_SizeChanged(object sender, SizeChangedEventArgs e)
            {
                messagePopup.Width = this.ActualWidth;
            }
    
            /// <summary>
            /// Invoked when this page is about to be displayed in a Frame.
            /// </summary>
            /// <param name="e">Event data that describes how this page was reached.  The Parameter
            /// property is typically used to configure the page.</param>
            protected override void OnNavigatedTo(NavigationEventArgs e)
            {
            }
    
            void okbtn_Click(object sender, RoutedEventArgs e)
            {
                if (messagePopup.IsOpen)
                    messagePopup.IsOpen = false;
                this.IsEnabled = true;
            }
    
            Popup messagePopup = new Popup();
            private void Button_Click_1(object sender, RoutedEventArgs e)
            {
                this.IsEnabled = false;
                messagePopup.VerticalOffset = (this.ActualHeight - messagePopup.ActualHeight) / 2;
                messagePopup.IsOpen = true;
            }


    Bob Bao [MSFT]
    MSDN Community Support | Feedback to us

    2012年6月11日 11:02
    版主