如何防止 window 在 uwp 中的特定宽度和高度后收缩
How to prevent window shrinking after a particular width and height in uwp
我正在开发 uwp 应用程序并希望使其响应。为此,我必须防止 window 在一定宽度和高度后缩小。有什么办法吗?我已经使用了 setpreferredminsize 属性,但它不起作用。
`
<Page
x:Class="Inventory.UWP.AuthenticatePage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Inventory.UWP"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls"
xmlns:extensions="using:Microsoft.Toolkit.Uwp.UI.Extensions"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" KeyDown="Page_KeyDown">
<Grid ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >
<Grid Margin="0" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >
<Grid.Background>
<ImageBrush ImageSource="login_backg.png" />
</Grid.Background>
<StackPanel Background="#FCF9F9" BorderBrush="#C1BFBF" BorderThickness="1" Height="411" Width="664" HorizontalAlignment="Center" VerticalAlignment="Center" >
<!--Header Image-->
<Image Source="login_header.png" Stretch="Uniform" />
<StackPanel Margin="-1,0,-1,0" Padding="0,0,0,0" Height="89" >
<Grid Height="88">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="22*"/>
<ColumnDefinition Width="53*"/>
</Grid.ColumnDefinitions>
<!--UserName and User TextBox-->
<TextBlock FontFamily="{StaticResource inventoryBoldFont}" FontSize="14" Text="Username" Margin="81,36,43,33" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
<Border Height="37" Width="341" Grid.Column="1" CornerRadius="5" BorderBrush="#C1BFBF" BorderThickness="0.5" Margin="1,20,77,19" >
<TextBox BorderThickness="0" Name="username" Text="" TextChanging="UsernameErrorMessageClear" Margin="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
</Border>
<TextBlock Grid.Column="1" Name="UserNameError" FontSize="12" Foreground="red" Margin="26,62,0,0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
</Grid>
</StackPanel>
<StackPanel Margin="-1,0,9,0" Padding="0,0,0,0" Height="89" >
<Grid Height="90">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="22*"/>
<ColumnDefinition Width="53*"/>
</Grid.ColumnDefinitions>
<!--Password and User TextBox-->
<TextBlock HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.Row="0" FontFamily="{StaticResource inventoryBoldFont}" FontSize="14" Text="Password" Width="57" Margin="81,31,54,40" />
<Border Margin="27,19,94,34" Height="37" Width="341" Grid.Row="0" Grid.Column="1" CornerRadius="5" BorderBrush="#C1BFBF" BorderThickness="0.5" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >
<PasswordBox Margin="0" BorderThickness="0" Name="userPassword" Password="" IsPasswordRevealButtonEnabled ="True" PasswordChanging="UserPassword_PasswordChanging" />
</Border>
<TextBlock Grid.Row="0" Grid.Column="1" Name="passwordError" FontSize="12" Foreground="red" Margin="27,58,47,0" />
</Grid>
</StackPanel>
<!--Login Button-->
<Button Width="228" Height="37" Content="LOGIN" FontSize="14" Foreground="White" FontWeight="Medium" Style="{StaticResource LoginBtnStyle }" Click="AuthenticateUser" Name="LoginBtn" HorizontalAlignment="Center" VerticalAlignment="Center" UseSystemFocusVisuals="True" PointerEntered="LoginBtn_PointerEntered" PointerExited="LoginBtn_PointerExited"></Button>
<!--Forget passwod link-->
<HyperlinkButton Foreground="#414042" HorizontalAlignment="Center" VerticalAlignment="Center" >
<HyperlinkButton.ContentTemplate>
<DataTemplate>
<TextBlock FontSize="12" FontFamily="{StaticResource inventoryRegularFont}" Text="Forgot your password?" />
</DataTemplate>
</HyperlinkButton.ContentTemplate>
</HyperlinkButton>
</StackPanel>
</Grid>
</Grid>
</Page>
`
我已经在上面给出了我的前端代码。请检查这个。
如果要限制最小window大小,可以使用SetPreferredMinSize
方法来限制。
ApplicationView.GetForCurrentView().SetPreferredMinSize(
new Size(
300, // Width
300 // Height
)
);
请注意
To remove the preferred minimum size and use and system default minimum size instead, set the Size value to "0,0".
The smallest allowed minimum size is 192 x 48 effective pixels. The largest allowed minimum size is 500 x 500 effective pixels. If you set a value outside of these bounds, it is coerced to be within the allowed bounds. (To learn about effective pixels, see Responsive design 101 for .)
我正在开发 uwp 应用程序并希望使其响应。为此,我必须防止 window 在一定宽度和高度后缩小。有什么办法吗?我已经使用了 setpreferredminsize 属性,但它不起作用。 `
<Page
x:Class="Inventory.UWP.AuthenticatePage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Inventory.UWP"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls"
xmlns:extensions="using:Microsoft.Toolkit.Uwp.UI.Extensions"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" KeyDown="Page_KeyDown">
<Grid ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >
<Grid Margin="0" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >
<Grid.Background>
<ImageBrush ImageSource="login_backg.png" />
</Grid.Background>
<StackPanel Background="#FCF9F9" BorderBrush="#C1BFBF" BorderThickness="1" Height="411" Width="664" HorizontalAlignment="Center" VerticalAlignment="Center" >
<!--Header Image-->
<Image Source="login_header.png" Stretch="Uniform" />
<StackPanel Margin="-1,0,-1,0" Padding="0,0,0,0" Height="89" >
<Grid Height="88">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="22*"/>
<ColumnDefinition Width="53*"/>
</Grid.ColumnDefinitions>
<!--UserName and User TextBox-->
<TextBlock FontFamily="{StaticResource inventoryBoldFont}" FontSize="14" Text="Username" Margin="81,36,43,33" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
<Border Height="37" Width="341" Grid.Column="1" CornerRadius="5" BorderBrush="#C1BFBF" BorderThickness="0.5" Margin="1,20,77,19" >
<TextBox BorderThickness="0" Name="username" Text="" TextChanging="UsernameErrorMessageClear" Margin="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
</Border>
<TextBlock Grid.Column="1" Name="UserNameError" FontSize="12" Foreground="red" Margin="26,62,0,0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
</Grid>
</StackPanel>
<StackPanel Margin="-1,0,9,0" Padding="0,0,0,0" Height="89" >
<Grid Height="90">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="22*"/>
<ColumnDefinition Width="53*"/>
</Grid.ColumnDefinitions>
<!--Password and User TextBox-->
<TextBlock HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.Row="0" FontFamily="{StaticResource inventoryBoldFont}" FontSize="14" Text="Password" Width="57" Margin="81,31,54,40" />
<Border Margin="27,19,94,34" Height="37" Width="341" Grid.Row="0" Grid.Column="1" CornerRadius="5" BorderBrush="#C1BFBF" BorderThickness="0.5" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >
<PasswordBox Margin="0" BorderThickness="0" Name="userPassword" Password="" IsPasswordRevealButtonEnabled ="True" PasswordChanging="UserPassword_PasswordChanging" />
</Border>
<TextBlock Grid.Row="0" Grid.Column="1" Name="passwordError" FontSize="12" Foreground="red" Margin="27,58,47,0" />
</Grid>
</StackPanel>
<!--Login Button-->
<Button Width="228" Height="37" Content="LOGIN" FontSize="14" Foreground="White" FontWeight="Medium" Style="{StaticResource LoginBtnStyle }" Click="AuthenticateUser" Name="LoginBtn" HorizontalAlignment="Center" VerticalAlignment="Center" UseSystemFocusVisuals="True" PointerEntered="LoginBtn_PointerEntered" PointerExited="LoginBtn_PointerExited"></Button>
<!--Forget passwod link-->
<HyperlinkButton Foreground="#414042" HorizontalAlignment="Center" VerticalAlignment="Center" >
<HyperlinkButton.ContentTemplate>
<DataTemplate>
<TextBlock FontSize="12" FontFamily="{StaticResource inventoryRegularFont}" Text="Forgot your password?" />
</DataTemplate>
</HyperlinkButton.ContentTemplate>
</HyperlinkButton>
</StackPanel>
</Grid>
</Grid>
</Page>
` 我已经在上面给出了我的前端代码。请检查这个。
如果要限制最小window大小,可以使用SetPreferredMinSize
方法来限制。
ApplicationView.GetForCurrentView().SetPreferredMinSize(
new Size(
300, // Width
300 // Height
)
);
请注意
To remove the preferred minimum size and use and system default minimum size instead, set the Size value to "0,0".
The smallest allowed minimum size is 192 x 48 effective pixels. The largest allowed minimum size is 500 x 500 effective pixels. If you set a value outside of these bounds, it is coerced to be within the allowed bounds. (To learn about effective pixels, see Responsive design 101 for .)