WPF Popup Full-screen popup method. Resolves a problem that only shows 75%.

Source: Internet
Author: User

A Popup in WPF has a feature. When the popup height exceeds 75% of the screen, only the height of 75% is displayed.

The following code:

<window x:class= "Wpfapplication13.mainwindow"        xmlns= "http://schemas.microsoft.com/winfx/2006/xaml/ Presentation "        xmlns:x=" Http://schemas.microsoft.com/winfx/2006/xaml "        title=" MainWindow "height=" 350 " Width= "525"         windowstate= "maximized" windowstyle= "None" >    <Grid>        <button content= "Open" click= "OnClick" width= "height=" "verticalalignment=" Bottom "/> <popup        x:name=" _popup "placement=" Absolute "width=" "height=" >            <Grid>                <Rectangle></Rectangle>                < TextBlock x:name= "_txt" text= "Testfullpopup"/>            </Grid>        </Popup>    </grid></ Window>
    <summary>//Interaction logic for MainWindow.xaml///    </summary> public    partial class Mainwindow:window    {public        MainWindow ()        {            InitializeComponent ();        }        private void OnClick (object sender, RoutedEventArgs e)        {            _popup. IsOpen =!_popup. IsOpen;        }    }

Display effect:

Look carefully, there is a control button, ah, probably only 75% of the style (I know beforehand!) Hey! )。 Let's look at the value on the Snoop again.

Really only 75%, 1080 * 0.75 = 810.

You can try all kinds of things. Height over 75% to see if the height is only 75%.

I also tried not to eject the popup from the 0,0 position and offset it from a distance. is still not possible. (Try it out, give me a minute)

And the size of the popup in CS is also invalid, I also tried to open a sub-thread, delay a period of time to set the height of the popup is also invalid.

Look at the Snoop, we can see the popuproot of the visual height, that is not can be modified, popuproot height to display. Modify the height to 1080, the success can be full screen.

So just set the Popuproot.height property on it!

The first thought is to use Visualtreehelper.getchild (); Gets the popuproot in the popup.

There are two questions: 1. Use Visualtreehelper.getchild (popup), with the child controls that do not get the popup.

The 2.PopupRoot may be an internal type. I didn't find it anyway! Please let me know if you find a classmate.

Had to use Visualtreehelper.getparent (), because did not find the Popuproot class, had to first use a string of judgment method. "System.Windows.Controls.Primitives.PopupRoot", directly on the code:

<summary>//Interaction logic for MainWindow.xaml///    </summary> public    partial class Mainwindow:window    {public        MainWindow ()        {            InitializeComponent ();        }        private void OnClick (object sender, RoutedEventArgs e)        {            _popup. IsOpen =!_popup. IsOpen;            DependencyObject parent = _popup. Child;            Do            {                parent = visualtreehelper.getparent (parent);                if (parent! = NULL && parent. ToString () = = "System.Windows.Controls.Primitives.PopupRoot")                {                    var element = parent as FrameworkElement;                    var mainwin = Application.Current.MainWindow;                    Element. Height = mainwin.height;                    Element. Width = Mainwin.width;                    break;                }            }            while (parent! = null);}    }

Final effect:

Knock it off, sleep.

Probably no one will turn, but the turn must indicate the source: http://www.cnblogs.com/gaoshang212/p/3157769.html

WPF Popup Full-screen popup method. Resolves a problem that only shows 75%.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.