Home > Mobile >  WPF : window size width cannot be changed smaller from the full/Max screen
WPF : window size width cannot be changed smaller from the full/Max screen

Time:09-23

Running below code will open app in full screen. clicking on the width button should change app width to 500 but its not changing to smaller. Is there anything else need to add?

MainWindow.xaml

<Window x:Class="WpfApp1.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"
        WindowState="Maximized"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800"
        SizeChanged="Window_SizeChanged">
    <StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center">
        <TextBox Text="500" x:Name="xwidth" Width="200" Margin="5"/>
        <Button Content="width change" Click="Button_Click" Width="200"/>

    </StackPanel>
</Window>

MainWindow.xaml.cs

namespace WpfApp1
{
   public partial class MainWindow : Window
    {

        public MainWindow()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            this.Width = System.Convert.ToDouble(xwidth.Text);
        }

        private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            Console.WriteLine("changed "    System.Convert.ToString(this.Width));
        }
    }
}

CodePudding user response:

WindowState is Maximized, change it to normal

private void Button_Click(object sender, RoutedEventArgs e){
    WindowState = WindowState.Normal;
    Width = Convert.ToDouble(xwidth.Text);
}
  • Related