Order of precedence for sizing-related properties that are implemented by Window. : Window « Windows Presentation Foundation « C# / C Sharp






Order of precedence for sizing-related properties that are implemented by Window.

Order of precedence for sizing-related properties that are implemented by Window.
   

<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="SizingPrecedenceSampleCSharp.MainWindow"
    Title="Sizing Sample" Height="300" Width="300" SizeToContent="WidthAndHeight">
  <StackPanel>
      <CheckBox Name="setWSCB" Content="Set WindowState?"/>
      <ComboBox Name="wsLB" IsEnabled="{Binding ElementName=setWSCB,Path=IsChecked}">
        <ComboBoxItem IsSelected="True">Minimized</ComboBoxItem>
        <ComboBoxItem>Maximized</ComboBoxItem>
        <ComboBoxItem>Normal</ComboBoxItem>
      </ComboBox>
      <CheckBox Name="setMinWidthCB" Content="Set MinWidth?"/>
      <TextBox Name="minWidthTB" IsEnabled="{Binding ElementName=setMinWidthCB,Path=IsChecked}">500</TextBox>
      <CheckBox Name="setMinHeightCB" Content="Set MinHeight?"/>
      <TextBox Name="minHeightTB" IsEnabled="{Binding ElementName=setMinHeightCB,Path=IsChecked}">500</TextBox>
      <CheckBox Name="setSTCCB" Content="Set SizeToContent?"/>
      <ComboBox Name="stcLB" IsEnabled="{Binding ElementName=setSTCCB,Path=IsChecked}">
        <ComboBoxItem IsSelected="True">Manual</ComboBoxItem>
        <ComboBoxItem>Width</ComboBoxItem>
        <ComboBoxItem>Height</ComboBoxItem>
        <ComboBoxItem>WidthAndHeight</ComboBoxItem>
      </ComboBox>
      <CheckBox Name="setMaxWidthCB" Content="Set MaxWidth?"></CheckBox>
      <TextBox Name="maxWidthTB" IsEnabled="{Binding ElementName=setMaxWidthCB,Path=IsChecked}">800</TextBox>
      <CheckBox Name="setMaxHeightCB" Content="Set MaxHeight?"></CheckBox>
      <TextBox Name="maxHeightTB" IsEnabled="{Binding ElementName=setMaxHeightCB,Path=IsChecked}">800</TextBox>
      <CheckBox Name="setWidthCB" Content="Set Width?"></CheckBox>
      <TextBox Name="widthTB" IsEnabled="{Binding ElementName=setWidthCB,Path=IsChecked}">700</TextBox>
      <CheckBox Name="setHeightCB" Content="Set Height?"></CheckBox>
      <TextBox Name="heightTB" IsEnabled="{Binding ElementName=setHeightCB,Path=IsChecked}">700</TextBox>
      <Button Click="showWindowButton_Click">Show Window</Button>
  </StackPanel>
</Window>

//File:Window.xaml.cs

using System;
using System.Windows;

namespace SizingPrecedenceSampleCSharp
{
    public partial class MainWindow : System.Windows.Window
    {

        public MainWindow()
        {
            InitializeComponent();
        }

        void showWindowButton_Click(object sender, RoutedEventArgs e)
        {
            MainWindow sw = new MainWindow();

            if (this.setWSCB.IsChecked == true) sw.WindowState = (WindowState)Enum.Parse(typeof(WindowState), this.wsLB.Text);
            if (this.setMinWidthCB.IsChecked == true) sw.MinWidth = double.Parse(this.minWidthTB.Text);
            if (this.setMinHeightCB.IsChecked == true) sw.MinHeight = double.Parse(this.minHeightTB.Text);
            if (this.setMaxWidthCB.IsChecked == true) sw.MaxWidth = double.Parse(this.maxWidthTB.Text);
            if (this.setMaxHeightCB.IsChecked == true) sw.MaxHeight = double.Parse(this.maxHeightTB.Text);
            if (this.setWidthCB.IsChecked == true) sw.Width = double.Parse(this.widthTB.Text);
            if (this.setHeightCB.IsChecked == true) sw.Height = double.Parse(this.heightTB.Text);
            if (this.setSTCCB.IsChecked == true) sw.SizeToContent = (SizeToContent)Enum.Parse(typeof(SizeToContent), this.stcLB.Text);

            sw.Show();
        }
    }
}

   
    
    
  








Related examples in the same category

1.Basic DialogBoxBasic DialogBox
2.Window ResizeMode=CanMinimizeWindow ResizeMode=CanMinimize
3.Window BackgroundWindow Background
4.Set Window Height and WidthSet Window Height and Width
5.Control the Size of UI Elements in a FormControl the Size of UI Elements in a Form
6.Define the Tab Order of UI Elements in a FormDefine the Tab Order of UI Elements in a Form
7.About DialogAbout Dialog
8.About Dialog - Font Properties on RootAbout Dialog - Font Properties on Root
9.Window mouse down eventWindow mouse down event
10.Window Preview mouse down eventWindow Preview mouse down event
11.Window mouse up eventWindow mouse up event
12.Window OwnershipWindow Ownership
13.Launch a window with defined XAMLLaunch a window with defined XAML
14.Hosting a Windows Forms Property Grid in WPFHosting a Windows Forms Property Grid in WPF
15.Window.DragMoveWindow.DragMove
16.Window.CommandBindingsWindow.CommandBindings
17.Create a non-rectangular windowCreate a non-rectangular window
18.Use Window Activated and Deactivated event to control a media fileUse Window Activated and Deactivated event to control a media file
19.Custom Element Binding WindowCustom Element Binding Window
20.ShutdownMode.OnLastWindowCloseShutdownMode.OnLastWindowClose
21.Window Loaded eventWindow Loaded event
22.Transparent WindowTransparent Window
23.Animated Video WindowAnimated Video Window
24.Close a window with Escape key pressedClose a window with Escape key pressed
25.Use WindowState to make full screen window, change resize mode to NoReSize
26.Window Closing and Closed eventWindow Closing and Closed event
27.Creating the main panel and add to Window in CodeCreating the main panel and add to Window in Code
28.Is Window activeIs Window active
29.Load the Data for a Window Asynchronously After It Has RenderedLoad the Data for a Window Asynchronously After It Has Rendered
30.Change window cursorChange window cursor
31.Show window based on button nameShow window based on button name
32.Listen to Window loaded eventListen to Window loaded event
33.Create Window and add window closing event handlerCreate Window and add window closing event handler
34.Activate window, close window, bring window to frontActivate window, close window, bring window to front
35.Do not handle events until Window is fully initialized.Do not handle events until Window is fully initialized.
36.Retrieving the mouse position relative to controls on a WindowRetrieving the mouse position relative to controls on a Window
37.Window On Mouse move eventWindow On Mouse move event
38.Window On Mouse up eventWindow On Mouse up event
39.Display window as dialogDisplay window as dialog
40.Load resource from Window ResourcesLoad resource from Window Resources
41.Windows Transparent BackgroundWindows Transparent Background
42.Save Window Position to RegistrySave Window Position to Registry
43.Center a Window to ScreenCenter a Window to Screen
44.Window Preview Key EventsWindow Preview Key Events
45.Non-Rectangular windowNon-Rectangular window
46.Set a Default ButtonSet a Default Button
47.Use the Grid to create a dialog box that uses the WPF layout APIUse the Grid to create a dialog box that uses the WPF layout API
48.ShowInTaskbar = false
49.SizeToContent=WidthAndHeight
50.ResizeMode=CanResizeWithGrip
51.Set the DataContext of a Window to a person objectSet the DataContext of a Window to a person object
52.DataContext with user defined object
53.Find owner window