WPF TextBox Stretching - wpf

I've got XAML below that shows what I want to do. It's pretty simply.
I have a Window that contains a grid. The grid contains a tab control with several tab items. The tab item shown below in the code contains a grid. The grid has two columns and six rows. Each row contains a label (column 0) and text box (column 1). I would like the label column to consume just as much space as needed. I want the text box column to consume the rest of the width of the row. And, as the user resizes the window horizontally, I want the text box column to contract and expand with the window. The code below does not do this, and I'm not sure what I need to do to fix this.
<Grid Background="#18AFA117">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Button Content="Generate" Grid.Row="1" Height="23" HorizontalAlignment="Left" Margin="54,8,0,0" Name="Generatebutton" VerticalAlignment="Top" Width="75" Click="Generatebutton_Click" />
<Button Content="Cancel" Height="23" HorizontalAlignment="Left" Margin="151,8,0,0" Name="CancelButton" VerticalAlignment="Top" Width="75" Grid.Row="1" Click="CancelButton_Click" />
<TabControl HorizontalAlignment="Stretch" Margin="5,5,5,416" Name="tabControl1" VerticalAlignment="Stretch" Height="Auto" SelectionChanged="tabControl1_SelectionChanged">
<TabItem Header="TFS Configuration" Name="TFSTab">
<Grid HorizontalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Label Content="TFS Server:" Grid.Column="0" Grid.Row="0" Height="25" HorizontalAlignment="Left" Margin="6,1,0,0" Name="label04" VerticalAlignment="Top" />
<Label Content="TFS Workspace Name:" Grid.Column="0" Grid.Row="1" Height="25" HorizontalAlignment="Left" Margin="6,1,0,0" Name="label05" VerticalAlignment="Top" />
<Label Content="TFS Local Folder:" Grid.Column="0" Grid.Row="2" Height="25" HorizontalAlignment="Left" Margin="6,1,0,0" Name="label06" VerticalAlignment="Top" />
<Label Content="TFS Framework Solution Path:" Grid.Column="0" Grid.Row="3" Height="25" HorizontalAlignment="Left" Margin="6,1,0,0" Name="label07" VerticalAlignment="Top" />
<Label Content="TFS Checkin Comments:" Grid.Column="0" Grid.Row="4" Height="25" HorizontalAlignment="Left" Margin="6,1,0,0" Name="label08" VerticalAlignment="Top" />
<Label Content="TFS Shelveset Name:" Grid.Column="0" Grid.Row="5" Height="25" HorizontalAlignment="Left" Margin="6,1,0,0" Name="label09" VerticalAlignment="Top" />
<TextBox Grid.Row="0" Grid.Column="1" Height="21" HorizontalAlignment="Stretch" Margin="13,3,0,0" Name="TFSServer" VerticalAlignment="Top"/>
<TextBox Grid.Row="1" Grid.Column="1" Height="21" HorizontalAlignment="Stretch" Margin="13,3,0,0" Name="TFSWorkspaceName" VerticalAlignment="Top" />
<TextBox Grid.Row="2" Grid.Column="1" Height="21" HorizontalAlignment="Stretch" Margin="13,3,0,0" Name="TFSLocalFolder" VerticalAlignment="Top" />
<ComboBox Grid.Row="3" Grid.Column="1" Height="23" HorizontalAlignment="Stretch" Margin="13,3,0,0" Name="TFSSolutionPaths" VerticalAlignment="Top" />
<TextBox Grid.Row="4" Grid.Column="1" Height="21" HorizontalAlignment="Stretch" Margin="13,3,0,0" Name="TFSCheckinComments" VerticalAlignment="Top" />
<TextBox Grid.Row="5" Grid.Column="1" Height="21" HorizontalAlignment="Stretch" Margin="13,3,0,0" Name="TFSShelvesetName" VerticalAlignment="Top" />
</Grid>
</TabItem>

Set the width of the column containing the textboxes to 'star': *
No need to set the textboxes' HorizontalAlignment to Stretch; the grid takes care of that.

Related

How to move window controls inside a TabItem in TabControl?

I've added a TabControl to my window in a WPF application, but I'm not sure how to re-position the TabControl so that all the other controls (buttons, textboxes, labels, data grid) are inside the General tab item.
I tried placing all my controls inside the TabItem element for the General Header, within a grid but I got a host of errors: http://hastebin.com/isenokidev.xml
Does anyone know how define this in XAML?
This is the xaml definition for the window with all the controls outside of the TabControl. I'm wondering how I can place them(in the same layout) within the general tab:
<Window x:Class="MongoDBApp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow"
Width="800"
Height="500">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="70" />
<RowDefinition Height="Auto" />
<RowDefinition Height="1*" />
<RowDefinition Height=".50*" />
<RowDefinition Height="1*" />
<RowDefinition Height="1*" />
<RowDefinition Height="1*" />
<RowDefinition Height="1*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1.25*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width=".50*" />
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width=".75*" />
</Grid.ColumnDefinitions>
<TabControl>
<TabItem Header="General">
</TabItem>
<TabItem Header="Security" />
<TabItem Header="Details" />
</TabControl>
<DataGrid Name="infogrid"
Grid.Row="0"
Grid.RowSpan="3"
Grid.Column="3"
Grid.ColumnSpan="4"
Width="356"
HorizontalAlignment="Left"
AutoGenerateColumns="True" />
<Label Grid.Row="4"
Grid.Column="3"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Content="First Name:" />
<TextBox Grid.Row="4"
Grid.Column="4"
Grid.ColumnSpan="2"
Width="120"
Height="23"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Text=""
TextWrapping="Wrap" />
<Label Grid.Row="5"
Grid.Column="3"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Content="Last Name:" />
<TextBox Grid.Row="5"
Grid.Column="4"
Grid.ColumnSpan="2"
Width="120"
Height="23"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Text=""
TextWrapping="Wrap" />
<Label Grid.Row="6"
Grid.Column="3"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Content="Department" />
<TextBox Grid.Row="6"
Grid.Column="4"
Grid.ColumnSpan="2"
Width="120"
Height="23"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Text=""
TextWrapping="Wrap" />
<Button x:Name="saveBtn"
Grid.Row="7"
Grid.Column="3"
Width="75"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Content="Save" />
<Button x:Name="updateBtn"
Grid.Row="7"
Grid.Column="4"
Width="75"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Content="Update" />
<Button x:Name="deleteBtn"
Grid.Row="7"
Grid.Column="5"
Width="75"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Content="Delete" />
</Grid>
</Window>
For all your controls to be in the General tab item, they need to be defined in it. I'm not sure why you were getting errors earlier, but this works fine:
<Grid>
<TabControl>
<TabItem Header="General">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="70" />
<RowDefinition Height="Auto" />
<RowDefinition Height="1*" />
<RowDefinition Height=".50*" />
<RowDefinition Height="1*" />
<RowDefinition Height="1*" />
<RowDefinition Height="1*" />
<RowDefinition Height="1*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width=".75*" />
</Grid.ColumnDefinitions>
<DataGrid Name="infogrid"
Grid.Row="0"
Grid.RowSpan="3"
Grid.ColumnSpan="4"
Width="356"
HorizontalAlignment="Left"
AutoGenerateColumns="True" />
<Label Grid.Row="4"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Content="First Name:" />
<TextBox Grid.Row="4"
Grid.Column="1"
Grid.ColumnSpan="2"
Width="120"
Height="23"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Text=""
TextWrapping="Wrap" />
<Label Grid.Row="5"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Content="Last Name:" />
<TextBox Grid.Row="5"
Grid.Column="1"
Grid.ColumnSpan="2"
Width="120"
Height="23"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Text=""
TextWrapping="Wrap" />
<Label Grid.Row="6"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Content="Department" />
<TextBox Grid.Row="6"
Grid.Column="1"
Grid.ColumnSpan="2"
Width="120"
Height="23"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Text=""
TextWrapping="Wrap" />
<Button x:Name="saveBtn"
Grid.Row="7"
Width="75"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Content="Save" />
<Button x:Name="updateBtn"
Grid.Row="7"
Grid.Column="1"
Width="75"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Content="Update" />
<Button x:Name="deleteBtn"
Grid.Row="7"
Grid.Column="2"
Width="75"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Content="Delete" />
</Grid>
</TabItem>
<TabItem Header="Security" />
<TabItem Header="Details" />
</TabControl>
</Grid>

Arrow Key Navigation in a WPF Form is Odd

I have a WPF form with which I would like to have arrow-key navigation. The current system is off, even though I have successfully specified the tab navigation order. I have two rows of three radio buttons. When I am on the middle button, top row, I should be able to hit the left arrow and select the first button of the top row; instead it selects the first button, bottom row. How do I correct this?
Update:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="20*"/>
<ColumnDefinition Width="80*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="15*"/>
<RowDefinition Height="15*"/>
<RowDefinition Height="15*"/>
<RowDefinition Height="30*"/>
<RowDefinition Height="25*"/>
</Grid.RowDefinitions>
<Label Grid.Column="0" Grid.Row="0" Content="Who:" VerticalAlignment="Top" HorizontalAlignment="Right" Margin="0,0,5,0" FontSize="12"/>
<Label Grid.Column="0" Grid.Row="1" Content="Caller:" VerticalAlignment="Top" HorizontalAlignment="Right" Margin="0,0,5,0" />
<Label Grid.Column="0" Grid.Row="2" Content="Office:" VerticalAlignment="Top" HorizontalAlignment="Right" Margin="0,0,5,0" />
<Label Grid.Column="0" Grid.Row="3" Content="Name:" VerticalAlignment="Top" HorizontalAlignment="Right" Margin="0,0,5,0" />
<Button Grid.Column="0" Grid.Row="4" Content="Find" VerticalAlignment="Bottom" HorizontalAlignment="Left" Margin="0,0,0,0" Width="50" Command="{Binding Path=FindCommand}" IsDefault="True" Click="Button_Click" TabIndex="9" />
<Grid Grid.Column="1" Grid.Row="0">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<RadioButton Content="All People" Grid.Column="0" HorizontalAlignment="Left" Margin="0,5,0,0" VerticalAlignment="Top" IsChecked="{Binding Path=IsPersonAll}" TabIndex="3" />
<RadioButton Content="Users Only" Grid.Column="1" HorizontalAlignment="Left" Margin="0,5,0,0" VerticalAlignment="Top" IsChecked="{Binding Path=IsPersonUser}" TabIndex="4" />
<RadioButton Content="Admin Only" Grid.Column="2" HorizontalAlignment="Left" Margin="0,5,0,0" VerticalAlignment="Top" TabIndex="5" />
</Grid>
<Grid Grid.Column="1" Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<RadioButton Content="Off Campus" Grid.Column="0" HorizontalAlignment="Left" Margin="0,5,0,0" VerticalAlignment="Top" IsChecked="{Binding Path=IsCallerOff}" TabIndex="6" />
<RadioButton Content="Admin" Grid.Column="1" HorizontalAlignment="Left" Margin="0,5,0,0" VerticalAlignment="Top" IsChecked="{Binding Path=IsCallerOnAd}" TabIndex="7" />
<RadioButton Content="User" Grid.Column="2" HorizontalAlignment="Left" Margin="0,5,0,0" VerticalAlignment="Top" TabIndex="8" />
</Grid>
<ComboBox
Grid.Column="1" Grid.Row="2"
Height="25" HorizontalAlignment="Stretch"
Margin="0,0,0,0" VerticalAlignment="Top"
ItemsSource="{Binding Path=Offices}"
SelectedItem="{Binding Path=Office}" TabIndex="2" />
<Grid Grid.Column="1" Grid.Row="3">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="55*"/>
<RowDefinition Height="45*"/>
<RowDefinition Height="50*"/>
</Grid.RowDefinitions>
<TextBox Name="lName" Grid.Column="0" Grid.Row="0" Margin="0,0,5,0" VerticalAlignment="Top" HorizontalAlignment="Stretch" Height="22" Text="{Binding Path=LastName, UpdateSourceTrigger=PropertyChanged}" TabIndex="0" />
<TextBox Grid.Column="1" Grid.Row="0" Margin="5,0,0,0" VerticalAlignment="Top" HorizontalAlignment="Stretch" Height="22" Text="{Binding Path=FirstName, UpdateSourceTrigger=PropertyChanged}" TabIndex="1" />
<Label Grid.Column="0" Grid.Row="1" Content="Last Name" HorizontalAlignment="Left" Margin="-5,-5,0,0" VerticalAlignment="Top" />
<Label Grid.Column="1" Grid.Row="1" Content="First Name" HorizontalAlignment="Left" Margin="0,-5,0,0" VerticalAlignment="Top" />
<Label Grid.Row="2" Grid.ColumnSpan="2" Content="Please supply search information in Department or Name." Foreground="Red" HorizontalAlignment="Stretch" Margin="-5,-5,0,0" VerticalAlignment="Top" Height="26" Visibility="{Binding Path=ErrVisibility}"/>
</Grid>
</Grid>
It's also for me kind of odd behaviour and after playing around with it i can tell you that it's caused by the HorizontalAlignment property, but i can't really explain why. Maybe someone else can shed some light on that.
Some more information:
In your case controls are focused alphabetically by the content property. You can easily test that by changing
<RadioButton Content="All People" Grid.Column="0" HorizontalAlignment="Left"
to
<RadioButton Content="Pall People" Grid.Column="0" HorizontalAlignment="Left"
After changing, controls are now focused correctly from right to left on first line because of alphabetical order: Users -> Pall People -> Off Campus.
As i was not aware of this behaviour i tried to reproduce by creating a new project with following XAML, but the behaviour of arrow keys was as expected, focusing the next neigbour in direction of the arrow key:
<Grid>
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<RadioButton Grid.Column="0" Content="All People"></RadioButton>
<RadioButton Grid.Column="1" Content="Users Only"></RadioButton>
<RadioButton Grid.Column="2" Content="Admin Only"></RadioButton>
</Grid>
<Grid Grid.Row="1">
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<RadioButton Grid.Column="0" Content="Off Campus"></RadioButton>
<RadioButton Grid.Column="1" Content="Admin"></RadioButton>
<RadioButton Grid.Column="2" Content="User"></RadioButton>
</Grid>
</Grid>
So i removed properties of the radio buttons of your xaml till i finally hit the point by removing HorizontalAlignment.
That XAML is now working as expected, at least for the radio buttons:
<Grid Grid.Column="1" Grid.Row="0">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<RadioButton Content="All People" Grid.Column="0" Margin="0,5,0,0" VerticalAlignment="Top" IsChecked="{Binding Path=IsPersonAll}" TabIndex="3" />
<RadioButton Content="Users Only" Grid.Column="1" Margin="0,5,0,0" VerticalAlignment="Top" IsChecked="{Binding Path=IsPersonUser}" TabIndex="4" />
<RadioButton Content="Admin Only" Grid.Column="2" Margin="0,5,0,0" VerticalAlignment="Top" TabIndex="5" />
</Grid>
<Grid Grid.Column="1" Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<RadioButton Content="Off Campus" Grid.Column="0" Margin="0,5,0,0" VerticalAlignment="Top" IsChecked="{Binding Path=IsCallerOff}" TabIndex="6" />
<RadioButton Content="Admin" Grid.Column="1" Margin="0,5,0,0" VerticalAlignment="Top" IsChecked="{Binding Path=IsCallerOnAd}" TabIndex="7" />
<RadioButton Content="User" Grid.Column="2" Margin="0,5,0,0" VerticalAlignment="Top" TabIndex="8" />
</Grid>

C# WPF Dynaically adding tabs byt loading xaml file clears radio buttons, why?

So I have a window that contains a TabControl as the main UI element. I add two tabs by default in the xaml editor. When the program runs I want to add new tabs that have identical setups (but are different than the first two tabs). I can do this by calling:
URLTabContentControl documentRoot = (URLTabContentControl)Application.LoadComponent(new Uri(#"URLTabContentControl.xaml", UriKind.Relative));
Which loads up a control I have defined in a xaml file. Basically this is what I want to show up inside of the new tab I will add. At this point I call:
TabItem ti = new TabItem();
ti.Header = "*New Capture URL " + (mainTabControl.Items.Count-1);
ti.Content = documentRoot;
int i = mainTabControl.Items.Add(ti);
mainTabControl.SelectedIndex = i;
Which creates the new TabItem adds a header and the control that was create via the xaml file. The issue is the xaml file has several different radio button groups and everytime I add a new tab the radio buttons on the existing tabs all become unselected. I don't think this is a bug in my code so I'm wondering if anyone can point me in the right direction. None of the other types of controls have their state screwed up like this.
This is the xaml that becomes the content of the TabItems:
<UserControl x:Class="CustomCamApplication.URLTabContentControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="340" d:DesignWidth="634">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="45*" />
<RowDefinition Height="42*" />
<RowDefinition Height="41*" />
<RowDefinition Height="31*" />
<RowDefinition Height="34*" />
<RowDefinition Height="29*" />
<RowDefinition Height="118*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="101*" />
<ColumnDefinition Width="105*" />
<ColumnDefinition Width="65*" />
<ColumnDefinition Width="45*" />
<ColumnDefinition Width="30*" />
<ColumnDefinition Width="88*" />
<ColumnDefinition Width="200*" />
</Grid.ColumnDefinitions>
<Label Content="URL Suffix:" Height="28" HorizontalAlignment="Right" Margin="0,12,0,0" Name="urlSuffixLabel" VerticalAlignment="Top" ToolTip="Enter the part of the path that will be after the domain. http://my.domain.com:port/(enter this part)" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="6,14,0,0" Name="textBox1" VerticalAlignment="Top" Width="401" Grid.Column="1" Grid.ColumnSpan="6" />
<Label Content="Video Source:" Height="28" HorizontalAlignment="Right" Margin="0,10,0,0" Name="videoSourceLabel" VerticalAlignment="Top" Grid.Row="1" ToolTip="Select the video source you want to use for this URL." />
<ComboBox Grid.Column="1" Height="23" HorizontalAlignment="Left" Margin="6,10,0,0" Name="videoSourceComboBox" VerticalAlignment="Top" Width="401" Grid.Row="1" Grid.ColumnSpan="6" SelectionChanged="videoSourceComboBox_SelectionChanged" />
<Label Content="Captured Image" Grid.Row="2" Height="28" HorizontalAlignment="Right" Margin="0,10,0,0" Name="capturedImageLabel" VerticalAlignment="Top" Width="101" />
<Label Content="Filename Prefix:" Grid.Column="1" Grid.Row="2" Height="28" HorizontalAlignment="Right" Margin="0,10,0,0" Name="filenamePrefixLabel" VerticalAlignment="Top" Width="95" ToolTip="Enter the front part of the file names used for capture file by this video source. Example prefix1002.png" />
<TextBox Grid.Column="2" Grid.Row="2" Height="23" HorizontalAlignment="Left" Margin="6,12,0,0" Name="filenamePrefixTextBox" VerticalAlignment="Top" Width="120" Text="capture" Grid.ColumnSpan="3" />
<Label Content="Capture Type:" Grid.Row="5" Height="28" HorizontalAlignment="Right" Name="captureTypeLabel" VerticalAlignment="Top" Width="83" ToolTip="Store only a single image or store a series of images on the drive." />
<RadioButton Content="Single Image" Grid.Column="1" Grid.Row="5" Height="16" HorizontalAlignment="Left" Margin="6,5,0,0" Name="captureTypeSingleRadioButton" VerticalAlignment="Top" GroupName="captureType" IsChecked="True" />
<RadioButton Content="Series" Grid.Column="2" Grid.Row="5" Height="16" HorizontalAlignment="Left" Margin="6,5,0,0" Name="captureTypeSeriesRadioButton" VerticalAlignment="Top" GroupName="captureType" />
<Label Content="File Format:" Grid.Column="1" Grid.Row="3" Height="28" HorizontalAlignment="Right" Margin="0,3,0,0" Name="captureFormatLabel" VerticalAlignment="Top" Width="73" ToolTip="Select the format of the stored capture files." />
<RadioButton Content="PNG" Grid.Column="2" Grid.Row="3" Height="16" HorizontalAlignment="Left" Margin="6,8,0,0" Name="fileFormatPNGRadioButton" VerticalAlignment="Top" GroupName="fileFormat" IsChecked="True" />
<RadioButton Content="JPG" Grid.Column="3" Grid.Row="3" Height="16" HorizontalAlignment="Left" Margin="0,8,0,0" Name="fileFormatJPGRadioButton" VerticalAlignment="Top" GroupName="fileFormat" />
<RadioButton Content="BMP" Grid.Column="4" Grid.Row="3" Height="16" HorizontalAlignment="Left" Margin="8,8,0,0" Name="fileFormatBMPRadioButton" VerticalAlignment="Top" GroupName="fileFormat" Grid.ColumnSpan="2" />
<CheckBox Content="Zero Pad Image Series Names" Grid.Column="5" Grid.Row="2" Height="16" HorizontalAlignment="Left" Margin="9,15,0,0" Name="filenameZeroPadCheckBox" VerticalAlignment="Top" ToolTip="Example prefix00001.png" Grid.ColumnSpan="2" />
<Label Content="Dimensions:" Grid.Column="1" Grid.Row="4" Height="28" HorizontalAlignment="Right" Margin="0,6,0,0" Name="captureDimensionsLabel" VerticalAlignment="Top" Width="73" />
<RadioButton Content="Source Default" Grid.Column="2" Grid.ColumnSpan="2" Grid.Row="4" Height="16" HorizontalAlignment="Left" Margin="6,11,0,0" Name="captureDimensionsDefaultRadioButton" VerticalAlignment="Top" Width="94" GroupName="captureDimensions" IsChecked="True" ToolTip="The default capture size for the selected video source." Checked="captureDimensionsDefaultRadioButton_Checked" />
<Label Content="Capture Interval:" Grid.Row="6" Height="28" HorizontalAlignment="Right" Margin="0,5,0,0" Name="captureIntervalLabel" VerticalAlignment="Top" Width="101" ToolTip="Enter the number of seconds between frame captures." />
<TextBox Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="6" Height="23" HorizontalAlignment="Left" Margin="6,7,0,0" Name="catureIntervalTextBox" VerticalAlignment="Top" Width="120" Text="5" PreviewTextInput="captureIntervalTextBox_PreviewTextInput" DataObject.Pasting="captureIntervalTextBox_Pasting"/>
<RadioButton Content="Reported Mode" Grid.Column="4" Grid.ColumnSpan="2" Grid.Row="4" Height="16" HorizontalAlignment="Left" Margin="8,11,0,0" Name="captureDimensionsSourceReportedRadioButton" VerticalAlignment="Top" GroupName="captureDimensions" ToolTip="Select a mode from one reported by the device." Checked="captureDimensionsSourceReportedRadioButton_Checked" />
<ComboBox Grid.Column="6" Grid.Row="4" Height="23" HorizontalAlignment="Left" Margin="0,6,0,0" Name="reportedModeComboBox" VerticalAlignment="Top" Width="174" IsEnabled="False" />
</Grid>
</UserControl>
Let's assume you have 3 groups of radio buttons on your URLTabContentControl control titled Group1, Group2, and Group3. When you dynamically create a TabItem based on URLTabContentControl that instance then has yet another group of radio buttons that have since expanded on your initial group definitions. Those 3 groups are not isolated to each instance per se.
One way to test this theory is to leave a single grouping of radio buttons on your URLTabContentControl control and remove the group name and let the framework handle the default behavior; it should work as expected now since there is no explicit group name tied to the radio buttons on URLTabContentControl

WPF Formatting Issues - Automatically stretching and resizing?

I'm very new to WPF and XAML. I am trying to design a basic data entry form. I have used a stack panel holding four more stack panels to get the layout I want. Perhaps a grid would be better for this, I am not sure.
And here is the XAML code that generates it:
<Window x:Class="Test1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="224" Width="536.762">
<StackPanel Height="Auto" Name="stackPanel1" Width="Auto" Orientation="Horizontal">
<StackPanel Height="Auto" Name="stackPanel2" Width="Auto">
<Label Height="Auto" Name="label1" Width="Auto">Patient Name:</Label>
<Label Height="Auto" Name="label2" Width="Auto">Physician:</Label>
<Label Height="Auto" Name="label3" Width="Auto">Insurance:</Label>
<Label Height="Auto" Name="label4" Width="Auto">Therapy Goals:</Label>
</StackPanel>
<StackPanel Height="Auto" Name="stackPanel3" Width="Auto">
<TextBox Height="Auto" Name="textBox1" Width="Auto" Padding="3" Margin="1" />
<TextBox Height="Auto" Name="textBox2" Width="Auto" Padding="3" Margin="1" />
<TextBox Height="Auto" Name="textBox3" Width="Auto" Padding="3" Margin="1" />
<TextBox Height="Auto" Name="textBox4" Width="Auto" Padding="3" Margin="1" />
</StackPanel>
<StackPanel Height="Auto" Name="stackPanel4" Width="Auto">
<Label Height="Auto" Name="label5" Width="Auto">Date:</Label>
<Label Height="Auto" Name="label6" Width="Auto">Patient Phone:</Label>
<Label Height="Auto" Name="label7" Width="Auto">Facility:</Label>
<Label Height="Auto" Name="label8" Width="Auto">Referring Physician:</Label>
</StackPanel>
<StackPanel Height="Auto" Name="stackPanel5" Width="Auto">
<TextBox Height="Auto" Name="textBox5" Width="Auto" Padding="3" Margin="1" />
<TextBox Height="Auto" Name="textBox6" Width="Auto" Padding="3" Margin="1" />
<TextBox Height="Auto" Name="textBox7" Width="Auto" Padding="3" Margin="1" />
<TextBox Height="Auto" Name="textBox8" Width="Auto" Padding="3" Margin="1" />
</StackPanel>
</StackPanel>
</Window>
What I really want is for the text boxes to stretch equally to fill up the space horizontally. I would also like for the controls in each vertical stackpanel to 'spread out' evenly as the window is resized vertically.
StackPanel always aligns its children against the top or left edge depending upon its orientation. It sounds like what you want is a UniformGrid where your outer StackPanel is. Try this:
<Window>
<UniformGrid Name="stackPanel1" Rows="1">
<StackPanel Name="stackPanel2">
...
</StackPanel>
<StackPanel Name="stackPanel3">
...
</StackPanel>
<StackPanel Name="stackPanel4">
...
</StackPanel>
<StackPanel Name="stackPanel5">
...
</StackPanel>
</UniformGrid>
</Window>
Note that you don't need to set Width=Auto or Height=Auto, this is implied.
But you are right that a Grid is probably better (even though the XAML is ugly) because in this layout configuration your labels could easily get out of alignment with the text boxes. You can try something like this too...
<UniformGrid Rows="1">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Label Grid.Row="0" Grid.Column="0" Content="Field 1" />
<TextBox Grid.Row="0" Grid.Column="1" />
<Label Grid.Row="1" Grid.Column="0" Content="Field 2" />
<TextBox Grid.Row="1" Grid.Column="1" />
<Label Grid.Row="2" Grid.Column="0" Content="Field 3" />
<TextBox Grid.Row="2" Grid.Column="1" />
</Grid>
<Grid /> <!-- repeat above -->
<Grid /> <!-- etc... -->
</UniformGrid>
Taking off what Josh said, if you require the controls to fill the space vertically as well, you can define some "space filler" rows to spread out the controls vertically as well. Here's some XAML which demonstrates this (I added margins to push the labels out from the window border).
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Label Grid.Column="0" Grid.Row="0" Margin="5">Patient Name:</Label>
<TextBox Grid.Column="1" Grid.Row="0" Margin="5" />
<Label Grid.Column="0" Grid.Row="2" Margin="5">Physician:</Label>
<TextBox Grid.Column="1" Grid.Row="2" Margin="5" />
<Label Grid.Column="0" Grid.Row="4" Margin="5">Insurance:</Label>
<TextBox Grid.Column="1" Grid.Row="4" Margin="5" />
<Label Grid.Column="0" Grid.Row="6" Margin="5">Therapy Goals:</Label>
<TextBox Grid.Column="1" Grid.Row="6" Margin="5" />
<Label Grid.Column="2" Grid.Row="0" Margin="5">Date:</Label>
<TextBox Grid.Column="3" Grid.Row="0" Margin="5" />
<Label Grid.Column="2" Grid.Row="2" Margin="5">Patient Phone:</Label>
<TextBox Grid.Column="3" Grid.Row="2" Margin="5" />
<Label Grid.Column="2" Grid.Row="4" Margin="5">Facility:</Label>
<TextBox Grid.Column="3" Grid.Row="4" Margin="5" />
<Label Grid.Column="2" Grid.Row="6" Margin="5">Referring Physician:</Label>
<TextBox Grid.Column="3" Grid.Row="6" Margin="5" />
</Grid>

WPF Grid Items and Right Aligned Text

I have a WPF form where I'm trying to make a simple input form. Two labels, two textboxes, and a "submit" button. I have the layout pretty good, the only thing that I can't get is for my "Labels" to be right aligned inside their cells. I have tried both TextAlign="Right" and HorizontialAlign="Right", that moves the text ALL the way over, overlaying my textbox, not just moving inside the cell. Below is the XAML for the window.
<Window x:Class="MyWebKeepAliveDesktop.Login"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MyWebKeepAlive Desktop - Login" WindowStyle="None" AllowsTransparency="true" Height="200" Width="400" >
<Border Background="#50FFFFFF" CornerRadius="7" BorderBrush="{StaticResource WindowFrameBrush}" BorderThickness="2,0,2,2">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="30" />
<RowDefinition/>
</Grid.RowDefinitions>
<Border Background="{StaticResource WindowFrameBrush}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
CornerRadius="5,5,0,0" Margin="-1,0,-1,0" MouseLeftButtonDown="DragWindow">
<Grid>
<TextBlock Foreground="White" FontWeight="Bold" VerticalAlignment="Center" Margin="10,2,10,2"
Text="MyWebKeepAlive Desktop Login"/>
<Button Content="X" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="5" FontSize="7"
Width="15" Height="15" Padding="0" Command="ApplicationCommands.Close"/>
</Grid>
</Border>
<Grid Grid.Row="1" Width="350" Height="130" HorizontalAlignment="Center" VerticalAlignment="Center">
<Grid.RowDefinitions>
<RowDefinition Height="35" />
<RowDefinition Height="25" />
<RowDefinition Height="25" />
<RowDefinition Height="10" />
<RowDefinition Height="30" />
</Grid.RowDefinitions>
<TextBlock TextAlignment="center" Text="Please provide your username/password that is used on the MyWebKeepAlive.com site to login." TextWrapping="Wrap" Grid.Row="0" Grid.ColumnSpan="2" />
<TextBlock Text="Username" FontWeight="Bold" Grid.Row="1" Grid.Column="0"/>
<TextBox Name="txtUsername" Width="150" Grid.Row="1" Grid.Column="1" />
<TextBlock Text="Password" FontWeight="Bold" Grid.Row="2" />
<TextBox Name="txtPassword" Width="150" Grid.Row="2" />
<Button Name="btnLogin" Grid.Row="4" Grid.ColumnSpan="2">
<TextBlock Text="Login" />
</Button>
</Grid>
</Grid>
</Border>
</Window>
Your grid only has one column as written. It will need two to support your setting of Grid.Column=1 for the text boxes. Thus, you need to add a <ColumnDefinitions> block. With the XAML the way it is now, WPF just throws both controls into the same column, hence the behavior you are seeing.
Here's what I came up with. Just learning WPF myself. As PeterAllenWebb mentioned, your main issue is you are missing the ColumnDefinitions. I also added the TextAlignment="Right" attributes to the two TextBlocks.
<Grid Grid.Row="1" Width="350" Height="130" HorizontalAlignment="Center" VerticalAlignment="Center">
<Grid.RowDefinitions>
<RowDefinition Height="35" />
<RowDefinition Height="25" />
<RowDefinition Height="25" />
<RowDefinition Height="10" />
<RowDefinition Height="30"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock TextAlignment="center" Text="Please provide your username/password that is used on the MyWebKeepAlive.com site to login." TextWrapping="Wrap" Grid.Row="0" Grid.ColumnSpan="2" />
<TextBlock Text="Username" TextAlignment="Right" FontWeight="Bold" Grid.Row="1" Grid.Column="0"/>
<TextBox Name="txtUsername" Width="150" Grid.Row="1" Grid.Column="1" />
<TextBlock Text="Password" TextAlignment="Right" FontWeight="Bold" Grid.Row="2" />
<TextBox Name="txtPassword" Width="150" Grid.Row="2" Grid.Column="1"/>
<Button Name="btnLogin" Grid.Row="4" Grid.ColumnSpan="2">
<TextBlock Text="Login" />
</Button>
</Grid>

Resources