Lets say I have a xaml for my window like this:
<Window x:Class="WavePoint_MVVM.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
FontSize="13"
FontFamily="Verdana"
xmlns:local="clr-namespace:WavePoint_MVVM"
Height="{Binding SystemParameters.PrimaryScreenHeigth}"
Width="{Binding SystemParameters.PrimaryScreenWidth}"
AllowsTransparency="False"
WindowStartupLocation="CenterScreen"
ResizeMode="CanResizeWithGrip"
<Grid/>
</Window>
Now I want to fix some sort of limit in which the user can't resize the window beyond it. Just to give an example, in Spotify app for Windows desktop, the user can't resize beyond a certain limit. This is the minimum I can get:
Thoughts?
To force a minimum window size, set your MinWidth and MinHeight attributes on the Window:
<Window x:Class="WavePoint_MVVM.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
FontSize="13"
FontFamily="Verdana"
xmlns:local="clr-namespace:WavePoint_MVVM"
Height="{Binding SystemParameters.PrimaryScreenHeigth}"
Width="{Binding SystemParameters.PrimaryScreenWidth}"
AllowsTransparency="False"
WindowStartupLocation="CenterScreen"
ResizeMode="CanResizeWithGrip"
MinWidth="640"
MinHeight="480">
<Grid/>
</Window>
Related
Have this simple XAML for a custom window. It works fine except during a resize (from the left, top, top-left and bottom-left) it looks awful. The window flashes like crazy. Doesn't seem like an OS issue as Microsoft's glass Windows app resize smooth as butter.
I'm trying to customize the window frame, but unless I use WindowChrome, I lose all the resizing, dragging, etc.
<Window x:Class="WpfApp2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp2"
WindowStyle="None"
mc:Ignorable="d"
WindowStartupLocation="CenterScreen"
Title="MainWindow" Height="450" Width="600">
<WindowChrome.WindowChrome>
<WindowChrome GlassFrameThickness="1,1,1,1" />
</WindowChrome.WindowChrome>
<Border BorderBrush="Red" BorderThickness="1">
<Button Content="Test" Height="25" Width="75" />
</Border>
</Window>
I made a WPF application in which. I placed a rectangle. The page is covering whole window but the size(width) of rectangle is not equal to the page.
here is the pic.
here is the source code of my application:
<Page x:Class="TestWpfApplication.Page1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:TestWpfApplication"
mc:Ignorable="d"
d:DesignHeight="350" d:DesignWidth="525"
Title="Page1" Background="#FF7ACBBC" ShowsNavigationUI="False">
<Grid>
<Rectangle Fill="#FFF4F4F5" HorizontalAlignment="Left" Height="100" Stroke="Black" VerticalAlignment="Top" Width="525"/>
<Label x:Name="label" Content="Heading" HorizontalAlignment="Left" Margin="222.006,25,0,0" VerticalAlignment="Top" FontFamily="Tahoma" FontSize="22"/>
<TextBlock x:Name="textBlock" HorizontalAlignment="Left" Margin="160,155,0,0" TextWrapping="Wrap" Text="And rest of the content goes here" VerticalAlignment="Top" FontFamily="Tahoma" FontSize="14"/>
</Grid>
And
<Window x:Class="TestWpfApplication.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:TestWpfApplication"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<local:Page1/>
</Grid>
At last App.xaml
<Application x:Class="TestWpfApplication.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:TestWpfApplication"
StartupUri="page1.xaml">
<Application.Resources>
</Application.Resources>
Please help me....
Set SizeToContent Property of Window to SizeToContent="WidthAndHeight"
SizeToContent
Page1.Xaml.cs:
public Page1()
{
InitializeComponent();
this.SizeToContent = SizeToContent.WidthAndHeight;
}
For more Info, See Window.SizeToContent Property
I don't know why you specified size parameters for rectangle and expect it to fit your page's size. Just remove all these parameters and it will stretch.
<Rectangle Fill="#FFF4F4F5"/>
I've already posted a message about this, but I've lost it! And I can paste code now too...
I have a RibbonRadioButton whose image is being stretched, XAML below (I haven't changed the code-behind from its default). I have checked that the PNG is at 96dpi but the problem remains.
XAML:
<Window x:Class="DashboardTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ribbon="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary"
Title="MainWindow" Height="350" Width="525">
<Grid>
<ribbon:Ribbon x:Name="Ribbon">
<ribbon:RibbonGroup x:Name="LiveStatusGroup"
Header="RibbonGroup Header">
<ribbon:RibbonRadioButton x:Name="Dashboard"
LargeImageSource="images\LiveStatus_Dashboard.png"
HorizontalContentAlignment="Center"
HorizontalAlignment="Center"
VerticalContentAlignment="Center"
VerticalAlignment="Center"
Label="RibbonRadioButton Label"
ToolTip="RibbonRadioButton ToolTip"/>
</ribbon:RibbonGroup>
</ribbon:Ribbon>
</Grid>
</Window>
Can anyone shed light on why this is happening? I am running Windows 7 with text size set to medium (125%).
J
I am having a problem with different appearance in Blend/VS2012 IDE and in Debugging.
In IDE, the Rectangle is at the center, but when it is compiled or debugged, the size of the margin is different. In my view, this occurs because the size of the window border is different. I really want to fix this problem. Any suggestions?
Thank You.
XAML
<Window x:Class="WpfApplication2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="202" Width="194">
<Grid HorizontalAlignment="Left" Height="171" VerticalAlignment="Top" Width="186">
<Rectangle Fill="#FFF4F4F5" HorizontalAlignment="Left" Height="151" Margin="10,10,0,0" Stroke="Black" VerticalAlignment="Top" Width="166"/>
</Grid>
Edited XAML code:
<Window x:Class="WpfApplication2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="202" Width="194">
<Grid HorizontalAlignment="Left" Height="171" VerticalAlignment="Top" Width="186">
<Rectangle Fill="#FFF4F4F5" HorizontalAlignment="Center" Height="151" Margin="10" Stroke="Black" VerticalAlignment="Center" Width="166"/>
</Grid>
Result is the same. Is this problem of my PC?
Your Problem here is Window Size includes the Chrome Size(Window Border and stuff like close/max min buttons).
Your Grid is hence the size you requested but it does not fit in the window size you've requested.
I could fix your issue to make the output window look like this, with Window size:
Width: 202
Height: 210
on Windows 8
However you should rather have your window size set to SizeToContent="WidthAndHeight"
Example:
<Window x:Class="WpfApplication4.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApplication4"
x:Name="window"
Title="MainWindow"
SizeToContent="WidthAndHeight">
<Grid HorizontalAlignment="Left" Height="171" VerticalAlignment="Top" Width="186">
<Rectangle Fill="#FFF4F4F5" HorizontalAlignment="Left" Height="151" Margin="10,10,0,0" Stroke="Black" VerticalAlignment="Top" Width="166"/>
</Grid>
</Window>
Your thus not assuming Chrome sizes which might be different from different versions of Windows.
You should also get Snoop. It helps you debug such issues very easily, It shows a red border on a control when you hover on it with Shift+Ctrl, so you can actually see the Grid extend past the visible Window while showing the actual Element Layout of your UI
Is it possible to hide the default resize grip in wpf, I have a custom window without handles on the sides and are currently using:
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="100" Width="200" ResizeMode="CanResizeWithGrip">
<Grid></Grid>
</Window>
I know it's possible to just change ResizeMode="CanResize" but this is the only way to resize the window that I can think of.
Yes you can take out the default resize grip from the Window. You need to override the WindowTemplate. Here is how you would do in XAML:
<Window x:Class="MyNamespace.MyWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
WindowStyle="None"
ResizeMode="CanResizeWithGrip"
AllowsTransparency="True">
<Window.Template>
<ControlTemplate>
<Border>
</Border>
</ControlTemplate>
</Window.Template>
</Window>
Within the "Border" will go everything that you need to display in the Window (e.g. a TextBox). Then if you want your custom ResizeGrip you can define that as well. Hope this helps.