Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. WPF C# Make window's the same width as the screen

WPF C# Make window's the same width as the screen

Scheduled Pinned Locked Moved WPF
csharpwpfwcftutorialquestion
8 Posts 4 Posters 5 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Acuena
    wrote on last edited by
    #1

    Hi! I am trying to make a window that when it starts, takes up the entire width of the screen, regardless of resolution. I have tried to set the Width to 100% and to bind it to the primary screen width

    Width="{Binding SystemParameters.PrimaryScreenWidth}">

    But neither worked :(. Anyone have any idea on how to do it?

    Have a nice day

    L Richard DeemingR 2 Replies Last reply
    0
    • A Acuena

      Hi! I am trying to make a window that when it starts, takes up the entire width of the screen, regardless of resolution. I have tried to set the Width to 100% and to bind it to the primary screen width

      Width="{Binding SystemParameters.PrimaryScreenWidth}">

      But neither worked :(. Anyone have any idea on how to do it?

      Have a nice day

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Try this: Window.WindowState Property (System.Windows) | Microsoft Docs[^].

      1 Reply Last reply
      0
      • A Acuena

        Hi! I am trying to make a window that when it starts, takes up the entire width of the screen, regardless of resolution. I have tried to set the Width to 100% and to bind it to the primary screen width

        Width="{Binding SystemParameters.PrimaryScreenWidth}">

        But neither worked :(. Anyone have any idea on how to do it?

        Have a nice day

        Richard DeemingR Offline
        Richard DeemingR Offline
        Richard Deeming
        wrote on last edited by
        #3

        Try:

        Width="{Binding Source={x:Static SystemParameters.PrimaryScreenWidth}}"

        c# - WPF Binding from System.Windows.SystemParameters.PrimaryScreenWidth with a Converter - Stack Overflow[^]


        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

        "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

        A 1 Reply Last reply
        0
        • Richard DeemingR Richard Deeming

          Try:

          Width="{Binding Source={x:Static SystemParameters.PrimaryScreenWidth}}"

          c# - WPF Binding from System.Windows.SystemParameters.PrimaryScreenWidth with a Converter - Stack Overflow[^]


          "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

          A Offline
          A Offline
          Acuena
          wrote on last edited by
          #4

          Hi! SO close :) It gives a very small gap between the screen edge and the window. I took a screenshot of the screen so that I could zoom in and check how many pixels there was between the window and the screen. It's around 8 pixels gap on the right side. And even if I set Left and Top to 0, I get one pixel from the top and 8 from the Left. Here is the XML code for the window that I have now:

          I would want it go to to the edge and there to be no gaps. Thanks for the help so far :)

          Have a nice day! Thinking of getting a new IDE!

          M L 2 Replies Last reply
          0
          • A Acuena

            Hi! SO close :) It gives a very small gap between the screen edge and the window. I took a screenshot of the screen so that I could zoom in and check how many pixels there was between the window and the screen. It's around 8 pixels gap on the right side. And even if I set Left and Top to 0, I get one pixel from the top and 8 from the Left. Here is the XML code for the window that I have now:

            I would want it go to to the edge and there to be no gaps. Thanks for the help so far :)

            Have a nice day! Thinking of getting a new IDE!

            M Offline
            M Offline
            Mycroft Holmes
            wrote on last edited by
            #5

            Is it possible you are looking for Kiosk mode? c# - WPF application in Kiosk mode - Stack Overflow[^]

            Never underestimate the power of human stupidity - RAH I'm old. I know stuff - JSOP

            1 Reply Last reply
            0
            • A Acuena

              Hi! SO close :) It gives a very small gap between the screen edge and the window. I took a screenshot of the screen so that I could zoom in and check how many pixels there was between the window and the screen. It's around 8 pixels gap on the right side. And even if I set Left and Top to 0, I get one pixel from the top and 8 from the Left. Here is the XML code for the window that I have now:

              I would want it go to to the edge and there to be no gaps. Thanks for the help so far :)

              Have a nice day! Thinking of getting a new IDE!

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              Create a (dummy) maximized window in the background and copy it's properties (e.g. width) to your actual "centered" window.

              It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food

              A 1 Reply Last reply
              0
              • L Lost User

                Create a (dummy) maximized window in the background and copy it's properties (e.g. width) to your actual "centered" window.

                It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food

                A Offline
                A Offline
                Acuena
                wrote on last edited by
                #7

                I was about to try Gerry's suggestion when I decided to test retriving the screen width with code and set the window size to it. It worked, but I wonder, is there not a way to do this without using code in WPF? Here is the code I used if someone is interested:

                this.Width = System.Windows.SystemParameters.PrimaryScreenWidth+2;

                Note that +2 is there since the Windows Left parameter in the XML are set to -2, had to compensate for that or I get a small gap to the right. I put it right below the "InitializeComponent();" call.

                Have a nice day! Thinking of getting a new IDE!

                Richard DeemingR 1 Reply Last reply
                0
                • A Acuena

                  I was about to try Gerry's suggestion when I decided to test retriving the screen width with code and set the window size to it. It worked, but I wonder, is there not a way to do this without using code in WPF? Here is the code I used if someone is interested:

                  this.Width = System.Windows.SystemParameters.PrimaryScreenWidth+2;

                  Note that +2 is there since the Windows Left parameter in the XML are set to -2, had to compensate for that or I get a small gap to the right. I put it right below the "InitializeComponent();" call.

                  Have a nice day! Thinking of getting a new IDE!

                  Richard DeemingR Offline
                  Richard DeemingR Offline
                  Richard Deeming
                  wrote on last edited by
                  #8

                  If you want to perform mathematical functions on the bound value, you'll need a converter - for example: GitHub - hexinnovation/MathConverter: A WPF Converter class that does it all[^]


                  "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                  "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups