<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();
}
}
}