I have a window in wpf that looks like this with no code-behind:
Now that my form looks like I want it to, I use the following to get data from my SQL Server database and load it into the form:
Private Sub winVehicleExpenses_Loaded(sender As Object, e As RoutedEventArgs) Handles winVehicleExpenses.Loaded
taVehicleExpenses = New PIMDataSetTableAdapters.taVehicleExpenses
taVehicleExpenses.Fill(dsPIM.VehicleExpenses) 'Load all the Expense data into the PIM dataset
Dim dvTypes As DataView = New DataView(dsPIM.Tables("StandardEntries"), "CategoryID = 13", "Entry", DataViewRowState.CurrentRows) 'CategoryID = 13 are the Vehicle Expense Types
With cboTypes
.ItemsSource = dvTypes
.SelectedIndex = 0 'Move to the first entry
End With
End Sub
Now when I run the application, here is what the form looks like:
Note the gap between the "Notes" label and the notes textboxes that was not there before the data were loaded.
How can the simple process of loading data into a listbox and some textboxes change the form layout?
ADDED: Here's the XAML
<Window
x:Class="VehicleExpenses"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="VehicleExpense"
xmlns:local="clr-namespace:PIM"
x:Name="winVehicleExpenses"
Height="490"
Width="440"
ShowInTaskbar="False"
Background="#FFE8FFFD"
IsTabStop="False">
<Window.Resources>
<local:DisplayDateFormatter x:Key="FormatDisplayDate" />
<local:DisplayCurrencyFormatter x:Key="FormatCurrency" />
<local:DisplayFixedFormatter x:Key="FormatSingle" />
<Style x:Key="ItemHeaders" TargetType="Label">
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="HorizontalContentAlignment" Value="Center" />
<Setter Property="Grid.Row" Value="1" />
<Setter Property="HorizontalAlignment" Value="Left" />
<Setter Property="VerticalAlignment" Value="Bottom" />
</Style>
<Style x:Key="ItemLabels" TargetType="Label">
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="HorizontalContentAlignment" Value="Right" />
<Setter Property="Height" Value="26" />
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Width" Value="80" />
<Setter Property="Margin" Value="0,5,0,0" />
</Style>
<Style x:Key="PreviousTextBoxes" TargetType="TextBox">
<Setter Property="Height" Value="26" />
<Setter Property="Margin" Value="0,5,0,0" />
<Setter Property="HorizontalAlignment" Value="Left" />
<Setter Property="Width" Value="80" />
<Setter Property="HorizontalContentAlignment" Value="Center" />
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Background" Value="Cornsilk" />
</Style>
<Style TargetType="Button">
<Setter Property="Height" Value="26" />
<Setter Property="Width" Value="60" />
<Setter Property="Margin" Value="60,0,0,0" />
<Setter Property="FontWeight" Value="Bold" />
</Style>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="40" />
<RowDefinition Height="30" />
<RowDefinition Height="225" />
<RowDefinition Height="100" />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="90"/>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<StackPanel
Grid.Column="0"
Grid.Row="0"
Grid.ColumnSpan="3"
Orientation="Horizontal"
HorizontalAlignment="Center">
<Label
Height="26"
FontWeight="Bold"
Content="Expense Type:" />
<ComboBox
Name="cboTypes"
Height="26"
Width="120"
FontSize="13"
DisplayMemberPath="Entry"
SelectedValuePath="EntryID"
Background="White" />
</StackPanel>
<Label
Grid.Column="0"
Content="Item"
Width="80"
Style="{StaticResource ItemHeaders}" />
<StackPanel
Grid.Column="0"
Grid.Row="2"
Height="220"
VerticalAlignment="Top">
<Label
Name="lblChargeDate"
Content="Charge Date:"
Style="{StaticResource ItemLabels}" />
<Label
Name="lblMileage"
Content="Mileage:"
Style="{StaticResource ItemLabels}" />
<Label
Name="lblGallons"
Content="Gallons:"
Style="{StaticResource ItemLabels}" />
<Label
Name="lblCharge"
Content="Charge:"
Style="{StaticResource ItemLabels}" />
<Label
Name="lblStartDate"
Content="Start Date:"
Style="{StaticResource ItemLabels}" />
<Label
Name="lblEndDate"
Content="End Date:"
Style="{StaticResource ItemLabels}" />
</StackPanel>
<Label
Content="Previous"
Grid.Column="1"
Width="93"
Style="{StaticResource ItemHeaders}" />
<Label
Content="Current"
Grid.Column="2"
Width="93"
Style="{StaticResource ItemHeaders}" />
<StackPanel
Name="pnlPrevious"
Grid.Column="1"
Grid.Row="2"
Height="220"
VerticalAlignment="Top">
<TextBox
Text="{Binding Path=ChargeDate, Converter={StaticResource FormatDisplayDate}}"
Style="{StaticResource PreviousTextBoxes}"
Focusable="False" />
<TextBox
Name="txtPreviousMileage"
Text="{Binding Path=Mileage}"
Style="{StaticResource PreviousTextBoxes}"
Focusable="False" />
<TextBox
Name="txtPreviousGallons"
Text="{Binding Path=Gallons, Converter={StaticResource FormatSingle}, ConverterParameter=3}"
Style="{StaticResource PreviousTextBoxes}"
Focusable="False" />
<TextBox
Text="{Binding Path=Charge, Converter={StaticResource FormatCurrency}}"
Style="{StaticResource PreviousTextBoxes}"
Focusable="False" />
<TextBox
Name="txtPreviousStartDate"
Text="{Binding Path=StartDate, Converter={StaticResource FormatDisplayDate}}"
Style="{StaticResource PreviousTextBoxes}"
Focusable="False" />
<TextBox
Name="txtPreviousEndDate"
Text="{Binding Path=EndDate, Converter={StaticResource FormatDisplayDate}}"
Style="{StaticResource PreviousTextBoxes}"
Focusable="False" />
<Label
Name="lblNotes"
Content="Notes:"
HorizontalAlignment="Right"
VerticalAlignment="Bottom"
Margin="0,0,30,0"
Style="{StaticResource ItemLabels}" />
</StackPanel>
<StackPanel
Grid.Column="2"
Grid.Row="2"
Height="220"
VerticalAlignment="Top">
<DatePicker
Name="dprCurrentChargeDate"
HorizontalAlignment="Left"
Height="23"
VerticalAlignment="Top"
Width="120" />
<TextBox
Name="txtCurrentMileage"
HorizontalAlignment="Left"
Height="23"
VerticalAlignment="Top"
Width="120" />
<TextBox
Name="txtCurrentsGallons"
HorizontalAlignment="Left"
Height="23"
VerticalAlignment="Top"
Width="120" />
<TextBox
Name="txtCurrentCharge"
HorizontalAlignment="Left"
Height="23"
VerticalAlignment="Top"
Width="120" />
<DatePicker
Name="dprCurrentStartDate"
HorizontalAlignment="Left"
Height="23"
VerticalAlignment="Top"
Width="120" />
<DatePicker
Name="dprCurrentEndDate"
HorizontalAlignment="Left"
Height="23"
VerticalAlignment="Top"
Width="120" />
</StackPanel>
<StackPanel
Grid.Column="0"
Grid.ColumnSpan="3"
Grid.Row="3"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"
Orientation="Horizontal">
<TextBox
Name="txtPreviousNotes"
VerticalAlignment="Stretch"
Width="175"
Text="{Binding Notes}"
Background="Cornsilk"
Focusable="False"
Margin="10,0,0,0"/>
<TextBox
Name="txtCurrentNotes"
VerticalAlignment="Stretch"
Width="175"
Margin="55,0,0,0" />
</StackPanel>
<StackPanel
Grid.Column="0"
Grid.Row="4"
Grid.ColumnSpan="3"
Orientation="Horizontal">
<Button
Name="btnCancel"
Content="Cancel"
IsTabStop="False" />
<Button
Name="btnClose"
Content="Close"
IsTabStop="False" />
<Button
Name="btnView"
Content="View"
IsTabStop="False" />
</StackPanel>
</Grid>