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.vb
Imports System
Imports System.Windows
Namespace SizingPrecedenceSampleCSharp
Public Partial Class MainWindow
Inherits System.Windows.Window
Public Sub New()
InitializeComponent()
End Sub
Private Sub showWindowButton_Click(sender As Object, e As RoutedEventArgs)
Dim sw As New MainWindow()
If Me.setWSCB.IsChecked = True Then
sw.WindowState = CType([Enum].Parse(GetType(WindowState), Me.wsLB.Text), WindowState)
End If
If Me.setMinWidthCB.IsChecked = True Then
sw.MinWidth = Double.Parse(Me.minWidthTB.Text)
End If
If Me.setMinHeightCB.IsChecked = True Then
sw.MinHeight = Double.Parse(Me.minHeightTB.Text)
End If
If Me.setMaxWidthCB.IsChecked = True Then
sw.MaxWidth = Double.Parse(Me.maxWidthTB.Text)
End If
If Me.setMaxHeightCB.IsChecked = True Then
sw.MaxHeight = Double.Parse(Me.maxHeightTB.Text)
End If
If Me.setWidthCB.IsChecked = True Then
sw.Width = Double.Parse(Me.widthTB.Text)
End If
If Me.setHeightCB.IsChecked = True Then
sw.Height = Double.Parse(Me.heightTB.Text)
End If
If Me.setSTCCB.IsChecked = True Then
sw.SizeToContent = CType([Enum].Parse(GetType(SizeToContent), Me.stcLB.Text), SizeToContent)
End If
sw.Show()
End Sub
End Class
End Namespace
Related examples in the same category