I want to set the window to an exact size for creating a game, since I will use the X and Y coordinates of the screen to move things. The problem is that when setting the window width and height it includes the border in that size, so your actual size is smaller than what you specify. What can I do about this?
You set the width and height to the panel inside of the window instead. Usually it's a Grid panel unless you have changed it. You can then set your window's SizeToContent property so it can autosize to fit the Grid.
Or you could do like this maybe: myForm.Width = yourValue + borderSize;
If your window is a WPF window try using AllowsTransparency="True" and WindowStyle="None"
Related
I have some textblocks included in a scroll viewer. I don't want to use the horizontal scrollbar so I came up with this idea but I don't know how to do this.
If you're referring to Screen size as the immediate window or page or just view of whatever in XAML you can easily bind the TextBlock.Width to the ActualWidth of that hosting element.
If you're talking about the actual monitor screen size then you just need to create a ViewModel with that property exposed and then bind that the same way.
If you need code let me know.
TextBlock has a property called TextWrapping. This will allow you the data in your TextBlock Not to overflow but increase the Height of TextBlock Itself. Also make sure to set VerticalAlignment to Stretch.
I'm very new to using WPF and having a problem on how to responsively resize the Grids when I set the Window State to maximized.
Please take a look on the design on the canvas when not Maximized:
http://imageshack.com/a/img921/3706/3E8e1F.png
and here's the look of Maximized window:
http://imageshack.com/a/img922/9510/0f2Dsq.png
set HorizontalAlignment="Streach" and VerticalAlignment="Streach"
remove harcoded height and width value.
Instead you can set MinHeight, MinWidth if required.
set margin accordingly if any set.
When I open a content dialog programmatically, the first objet catching the focus and the content dialog's shape was distorted.
Are any way available show the keyboard on the content dialog without distort the general shape ?
Thanks.
Screenshot:
When the keyboard shows, the ContentDialog will adjust its height automatically. And this will cause the change of ContentDialog's Content's height. So when the keyboard shows, the Content's height becomes small and the rest of the Content is blocked.
If you want the keyboard shows without distorting the general shape, you can set the MinHeight property of ContentDialog. For example, you can give ContentDialog a large MinHeight like "500"
<ContentDialog x:Name="contentDialog" MinHeight="500" />
Or
contentDialog.MinHeight = 500;
After this, when the ContentDialog adjust its height, its height will be 500 at least and if this height is large enough, it will not distort the general shape. You may set the MinHeight equal to ContentDialog's default height to make sure it's large enough.
I am using a WPF Window with contains a frame where I add the content of different pages I have.
The problem is that all of these pages have the same Width but different Height.
So what I would like to do is to be able to set the window's height, to the height of the page inside of the window's frame.
Thanks
Changing the window height, aside from looking horrible to the end user, comes with all sorts of complications. For example, what if your content has a greater height than the screen can display? Would your window go off the screen?
A better option may be to look into a control that gives a scroll bar if the content exceeds the window height.
In wpf you can set window property
SizeToContent="WidthAndHeight"
or
SizeToContent="Height"
As #Joeb454 already answered this may looks horrible during navigation (user-experience-wise).
Is there a way to get the size at runtime ?
I need to display the usercontrol in a dialog and need to size the window accordingly
Since there are multiple usercontrols, looking for make it generic if possible !!
Sounds like you might need to rethink the problem? If you need the design time height and width, then just set the Width and Height of the control you are working with explicitly. This will 'default' the control to a specific size. Normally, you'd probably want the control's width and height to be set to Auto and have the container or layout manager decide what the size should be. So if you put the control in a Grid, assign it to a quadrant and set the size there.
Finally, if you're asking because you are designing with Blend and resizing the user control sets the design time, you can resize the control explicitly by selecting the inside corner notch instead of the outside corner notch with the bigger handle. The inside notch will result in Height and Width being set explicitly.
You can use SizeToContent
<Window x:Class="WindowSample.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="WPF Window"
SizeToContent="WidthAndHeight" >
This will make your window automatically resize itself to fit the preferred size of your window contents.