XAML DataTemplate with parameter - wpf

I have a data template that is:
<DataTemplate x:Key="CalDescButton">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock
Grid.Row="0"
Grid.RowSpan="2"
Grid.Column="0"
Grid.ColumnSpan="2"
Style="{StaticResource LargeIconStyle}"
Text="" />
<TextBlock
Grid.Row="0"
Grid.Column="1"
Foreground="Transparent"
Style="{StaticResource MediumIconStyle}"
Text="" />
<TextBlock
Grid.Row="1"
Grid.Column="1"
Foreground="Transparent"
Style="{StaticResource MediumIconStyle}"
Text="" />
<TextBlock
Grid.Row="0"
Grid.Column="1"
Foreground="Transparent"
Style="{StaticResource MediumIconStyle}"
Text="" />
<TextBlock
Grid.Row="1"
Grid.Column="0"
Foreground="Transparent"
Style="{StaticResource MediumIconStyle}"
Text="" />
<TextBlock
Grid.Row="1"
Grid.RowSpan="2"
Grid.Column="0"
Margin="0,-6,0,0"
Foreground="Aqua"
Style="{StaticResource XSmallIconStyle}"
Text="" />
</Grid>
</DataTemplate>
Then I have other 6 where the only thing that changes is the Text Char code.
Those templates are applied to buttons:
<ToggleButton
Command="{Binding CmdSetSorting, Mode=OneWay}"
CommandParameter="CalAsc"
ContentTemplate="{StaticResource CalDescButton}" />
The question is: can I pass a variable to the template and use it in the Text="" instead of having 6 different templates just for that?
How can I do it?
Just to be clear I'd like to have something like:
<DataTemplate x:Key="IconButton">
and then:
ContentTemplate="{StaticResource IconButton ()}" />

set Content property of Button:
<ToggleButton
Command="{Binding CmdSetSorting, Mode=OneWay}"
CommandParameter="CalAsc"
Content=""
ContentTemplate="{StaticResource CalDescButton}" />
it should become DataContext of root element in DataTemplate (because it is ContentTemplate) and will be accessible by Binding:
<TextBlock
Grid.Row="0"
Grid.RowSpan="2"
Grid.Column="0"
Grid.ColumnSpan="2"
Style="{StaticResource LargeIconStyle}"
Text="{Binding}" />

Related

Avoid XAML Dependency Property to read while Collapsed

On a ViewModel a property of "OperationStepInstance" is commanding a huge process if asking for its value.
My question is, if there is a way to not ask for its value while in XAML the element is hidden or collapsed.
By default, even if it is collapsed, a Dependency property is always asked for its value.
<Grid Grid.Row="3" HorizontalAlignment="Center" Visibility="{Binding Path=StatusInstance.IsProductive, Converter={StaticResource BoolToVis}}" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding Path=ProductionOrderInstance.Key}" Grid.Column="0" Style="{StaticResource ItemTextStyle}" />
<TextBlock Text="-" Grid.Column="1" Style="{StaticResource ItemTextStyle}" Margin="4,0,4,0" />
<TextBlock Text="{Binding Path=ProductionOrderInstance.OperationStepInstance.Number}" Grid.Column="2" Style="{StaticResource ItemTextStyle}" />
<TextBlock Text="/" Grid.Column="3" Style="{StaticResource ItemTextStyle}" Margin="4,0,0,0" />
<TextBlock Text="{Binding Path=StatusInstance.Key}" Grid.Column="4" Style="{StaticResource ItemTextStyle}" Margin="4,0,4,0" />
<TextBlock Text="" Grid.Column="5" Style="{StaticResource ItemTextStyle}" Margin="0,0,0,0" />
</Grid>

Listbox last element incorrect rendering

I got trouble with the listbox. Please, check the screenshot down there. The last element is kind of "eaten" by the listbox external border (I defined appropriate MaxHeight). Can someone help me?
<DataTemplate x:Key="QCTemplate">
<Grid>
<Expander x:Name="expander" Header="{Binding}">
<Expander.HeaderTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical">
<TextBox Name="ComponentNameTextBlock" Style="{StaticResource BorderlessTextBoxStyle}" Text="{Binding ComponentName, Mode=TwoWay}" />
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Margin="1">Количество цитат:</TextBlock>
<TextBlock Name="ComponentVolumeTextBlock" Grid.Column="1" Margin="1" Text="{Binding Volume}" />
</Grid>
</StackPanel>
</DataTemplate>
</Expander.HeaderTemplate>
<!-- Контекстное меню экспандера -->
<Expander.ContextMenu>
<ContextMenu>
<MenuItem Header="Оригинал 'My Clippings.txt'">
<MenuItem Header="Удалить из оригинала..."
Command="{StaticResource ResourceKey=DeleteFromMyClippingsCommand}"
CommandParameter="{Binding}" />
</MenuItem>
</ContextMenu>
</Expander.ContextMenu>
<!-- Внутреннее содержание экспандера -->
<Grid Name="ExpanderContentContainer"
Height="{Binding ElementName=ComponentChildsListBox, Path=ActualHeight}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="25" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Rectangle Grid.Column="0" Grid.Row="0"
Width="2" Height="{Binding Path=ActualHeight}"
Fill="Black"
Margin="2"
/>
<StackPanel Orientation="Vertical"
Grid.Column="1" Grid.Row="0">
<TextBox Name="ComponentCommentTextBox"
Text="{Binding Comment, Converter={StaticResource ResourceKey=QCCCommentConvrtr}, Mode=TwoWay}"
BorderThickness="0"
GotFocus="ComponentCommentTextBox_GotFocus"
Margin="1"
/>
<ListBox Name="ComponentChildsListBox"
BorderBrush="Transparent"
ItemsSource="{Binding ChildsCollection}"
ScrollViewer.CanContentScroll="False"
MaxHeight="300"
Margin="1"
Style="{StaticResource LibraryViewListBoxStyle}"
/>
</StackPanel>
</Grid>
</Expander>
</Grid>
</DataTemplate>
Screenshot

TextBlock TextWrapping not wrapping inside StackPanel

I have a StackPanel, but the following line :
<TextBlock Grid.Row="1" Grid.Column="0" Text="{Binding Notes}" TextWrapping="Wrap" />
is not Wrapping the Text.
<StackPanel Orientation="Vertical">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="5" />
<ColumnDefinition Width="15" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<DockPanel Grid.Row="0" Grid.Column="0">
<TextBlock FontWeight="Bold" Padding="0,0,5,0" Text="{Binding Path=Id, StringFormat='#\{0\}'}" />
<TextBlock FontWeight="Bold" Padding="0,0,5,0" Text="{Binding Path=Name}" />
</DockPanel>
<TextBlock Grid.Row="0" Grid.Column="4" FontWeight="Bold" Text="{Binding Path=Time, StringFormat={}{0:HH:mm}}" />
<Image
Grid.Row="0"
Grid.Column="6"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Source="{Binding Path=Image, Mode=OneWay, Converter={StaticResource ImageConverter}}" />
<TextBlock Grid.Row="1" Grid.Column="0" Text="{Binding Notes}" TextWrapping="Wrap" />
<Image
Grid.Row="1"
Grid.Column="4"
HorizontalAlignment="Center"
VerticalAlignment="Top"
Source="{Binding Path=Picture, Mode=OneWay, Converter={StaticResource PictureConverter}}" />
</Grid>
</StackPanel>
The StackPanel Orientation is set to 'Vertical' but the TextBlock is not inheriting it.
Where am I going wrong?
Your problem is using the StackPanel that allows its children to fill in all the available space - the StackPanel stretches accordingly to the size of its content. Try removing the StackPanel and keep just the Grid - this way you will limit the size of its children to the available space used by the Grid.
If that isn't enough in the layout you've built, try setting a MaxWidth on the TextBox that needs wrapping.
Now the source of your problem was also the fact that your TextBox was inserted in the first Column of the Grid that had an infinite size (Width="Auto"). Thus, setting the Grid.Column="7" to the TextBox did the trick you wanted (wrapping text). Here's the revised code:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="5" />
<ColumnDefinition Width="15" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<DockPanel Grid.Row="0" Grid.Column="0">
<TextBlock FontWeight="Bold" Padding="0,0,5,0" Text="{Binding Path=Id, StringFormat='#\{0\}'}" />
<TextBlock FontWeight="Bold" Padding="0,0,5,0" Text="{Binding Path=Name}" />
</DockPanel>
<TextBlock Grid.Row="0" Grid.Column="4" FontWeight="Bold" Text="{Binding Path=Time, StringFormat={}{0:HH:mm}}" />
<Image
Grid.Row="0"
Grid.Column="6"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Source="{Binding Path=Image, Mode=OneWay, Converter={StaticResource ImageConverter}}" />
<TextBlock Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="7" Text="{Binding Notes}" TextWrapping="Wrap" />
<Image
Grid.Row="1"
Grid.Column="4"
HorizontalAlignment="Center"
VerticalAlignment="Top"
Source="{Binding Path=Picture, Mode=OneWay, Converter={StaticResource PictureConverter}}" />
</Grid>

Now that I know where the focus is going to, how do I figure out why it's going there?

I have a search screen in my WPF application. The screen is implemented as a UserControl in a TabItem of a TabControl. When the user switches to the Search tab, I want the focus to go into one particular field. I asked a question here about how to figure out where the focus was going to. I now know where it's going. Now I want to figure out why it's going there so I can stop it.
Note that the focus is changing spontaneously and has nothing to do with any user activity. All the user has done is click on the search tab in the main window. The focus is supposed to go to this one particular text box; this is done in the UserControl's Loaded event handler. And it does go to that TextBox initially. Then, for some reason, it goes to the CheckBox.
I have assigned values to the TabIndex controls on my form that the user can interact with. The CheckBox is at TabIndex 1. The TextBox in question is at TabIndex 9. This is also the only TextBox on the form.
In the past, the focus would move to the TextBox and stay there. Without realizing it, I changed something that causes the focus to go to the CheckBox. I don't know what it was that I changed, exept that it was at about the time I upgraded the Telerik controls library to the latest version.
Here is the Xaml for the whole control, minus some stuff that wouldn't matter:
<UserControl x:Class="CarSystem.CustomControls.Searcher"
<!-- XML Namespaces removed for brevity -->
Height="620"
Loaded="UserControl_Loaded"
Width="990">
<UserControl.Resources>
<!--- Resource removed for brevity -->
</UserControl.Resources>
<Grid Background="{DynamicResource ContentBackground}"
FocusManager.IsFocusScope="True"
Name="LayoutRoot">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="110" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid Grid.Column="0"
Grid.Row="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<GroupBox BorderBrush="{DynamicResource ControlBorder}"
FontSize="16"
FontWeight="Bold"
Foreground="{DynamicResource TextForeground}"
Grid.Column="0"
Grid.Row="0"
Header="Alarm Class:"
Margin="5,0">
<Grid VerticalAlignment="Center">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="35" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<CheckBox Click="AllAlarmClasses_Click"
Content="ALL"
FontSize="14"
FontWeight="Bold"
Grid.Column="0"
Grid.Row="0"
HorizontalAlignment="Left"
Margin="5"
Name="AllAlarmClasses"
TabIndex="1"
VerticalAlignment="Center" />
<Button Background="{DynamicResource ButtonBackground}"
Click="ExpandPicker_Click"
Content="Expand"
FontSize="14"
FontWeight="Bold"
Grid.Column="1"
Grid.Row="0"
Foreground="{DynamicResource ButtonForeground}"
Margin="5"
Name="ExpandAlarmClass"
TabIndex="2" />
<ListBox BorderBrush="Black"
BorderThickness="1"
CheckBox.Click="AlarmClassPicker_Click"
ItemTemplate="{StaticResource CheckableChoice}"
FontSize="14"
FontWeight="Bold"
Grid.Column="0"
Grid.ColumnSpan="2"
Grid.Row="1"
Height="100"
ItemsSource="{Binding Path=AlarmClassChoices, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}, Mode=TwoWay}"
Margin="5,0"
Name="AlarmClassPicker"
SelectionMode="Multiple"
TabIndex="3"
Visibility="Collapsed" />
</Grid>
</GroupBox>
<GroupBox BorderBrush="{DynamicResource ControlBorder}"
FontSize="16"
FontWeight="Bold"
Foreground="{DynamicResource TextForeground}"
Grid.Column="0"
Grid.Row="1"
Header="Source:"
Margin="5,0">
<cs:TouchComboBox Background="{DynamicResource UnfocusedBackground}"
BorderBrush="{DynamicResource ControlBorder}"
FontSize="14"
FontWeight="Bold"
Foreground="{DynamicResource UnfocusedForeground}"
GridBackground="{DynamicResource ContentBackground}"
Height="50"
IsTabStop="True"
ItemsSource="{Binding Path=HotListChoices, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}, Mode=TwoWay}"
Margin="5,0"
x:Name="HotListPicker"
SelectionChanged="SourcePicker_SelectionChanged"
TabIndex="4"
TimeOfDayMode="{Binding Path=TimeOfDayMode, RelativeSource={RelativeSource AncestorType={x:Type cs:Searcher}}}"
VerticalAlignment="Top" />
</GroupBox>
<GroupBox BorderBrush="{DynamicResource ControlBorder}"
FontSize="16"
FontWeight="Bold"
Foreground="{DynamicResource TextForeground}"
Grid.Column="1"
Grid.Row="0"
Header="Start Date:"
Margin="5,0">
<telerik:RadDateTimePicker FontWeight="Bold"
Height="35"
Margin="5"
Name="StartDatePicker"
SelectionChanged="DateTimePicker_SelectionChanged"
Style="{DynamicResource RadDateTimePickerControlTemplate1}"
TabIndex="5"
VerticalAlignment="Center" />
</GroupBox>
<GroupBox BorderBrush="{DynamicResource ControlBorder}"
FontSize="16"
FontWeight="Bold"
Foreground="{DynamicResource TextForeground}"
Grid.Column="1"
Grid.Row="1"
Header="End Date:"
Margin="5,0">
<telerik:RadDateTimePicker FontSize="14"
FontWeight="Bold"
Height="35"
Margin="5"
Name="EndDatePicker"
SelectionChanged="DateTimePicker_SelectionChanged"
Style="{DynamicResource RadDateTimePickerControlTemplate1}"
TabIndex="6"
VerticalAlignment="Center" />
</GroupBox>
<GroupBox BorderBrush="{DynamicResource ControlBorder}"
FontSize="16"
FontWeight="Bold"
Foreground="{DynamicResource TextForeground}"
Grid.Column="2"
Grid.Row="0"
Header="State:"
Margin="5,0">
<cs:TouchComboBox Background="{DynamicResource UnfocusedBackground}"
BorderBrush="{DynamicResource ControlBorder}"
DisplayMemberPath="Value"
FontSize="14"
FontWeight="Bold"
Foreground="{DynamicResource UnfocusedForeground}"
GridBackground="{DynamicResource ContentBackground}"
Height="50"
ItemsSource="{Binding Path=LocaleChoices, Mode=TwoWay, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"
Margin="5"
x:Name="StatePicker"
SelectedValue="{Binding Path=LocaleCode}"
SelectedValuePath="Key"
SelectionChanged="StatePicker_SelectionChanged"
TabIndex="7"
TimeOfDayMode="{Binding Path=TimeOfDayMode, RelativeSource={RelativeSource AncestorType={x:Type cs:Searcher}}}"
VerticalAlignment="Center" />
</GroupBox>
<GroupBox BorderBrush="{DynamicResource ControlBorder}"
FontSize="16"
FontWeight="Bold"
Foreground="{DynamicResource TextForeground}"
Grid.Column="2"
Grid.Row="1"
Header="Plate:"
Margin="5,0">
<Border BorderBrush="{DynamicResource ControlBorder}"
BorderThickness="1"
Height="35"
Margin="5"
VerticalAlignment="Center">
<TextBox FontSize="14"
FontWeight="Bold"
GotFocus="PlateBox_GotFocus"
LostFocus="PlateBox_LostFocus"
Margin="-1"
MaxLength="25"
MaxLines="1"
Name="PlateBox"
TabIndex="8"
Text="{Binding Path=Plate, Mode=TwoWay}"
TextChanged="PlateBox_TextChanged"
ToolTip='Wildcards ("%", "_", "[", "]") can be used' />
</Border>
</GroupBox>
</Grid>
<TabControl Background="{DynamicResource TabBackground}"
Grid.Row="1"
Margin="0,20,0,5"
Name="ResultTabs"
TabIndex="9">
<TabItem Background="{DynamicResource TabHeaderBackground}"
FontSize="16"
FontWeight="Bold"
Foreground="{DynamicResource TabHeaderForeground}"
Header="Hot List Entries:"
Name="HotListEntryTab">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<telerik:RadGridView AutoExpandGroups="True"
AutoGenerateColumns="False"
CanUserDeleteRows="False"
CanUserFreezeColumns="False"
CanUserInsertRows="False"
CanUserResizeColumns="True"
CanUserSortColumns="True"
EnableColumnVirtualization="True"
EnableRowVirtualization="True"
FontSize="14"
FontWeight="Bold"
IsReadOnly="True"
Name="HotListEntriesGrid"
SelectionChanged="HotListEntriesGrid_SelectionChanged"
SelectionUnit="FullRow"
ScrollViewer.CanContentScroll="True"
ScrollViewer.HorizontalScrollBarVisibility="Auto"
ScrollViewer.VerticalScrollBarVisibility="Auto"
TabIndex="10"
ToolTip="Matching Hot List Entries">
<telerik:RadGridView.Columns>
<telerik:GridViewDataColumn DataMemberBinding="{Binding Plate, Mode=OneWay}"
Header="Plate"
Width="*" />
<telerik:GridViewDataColumn DataMemberBinding="{Binding LocaleCode, Mode=OneWay}"
Header="State"
Width="75" />
<telerik:GridViewDataColumn DataMemberBinding="{Binding ListName, Mode=OneWay}"
Header="Source"
Width="150" />
<telerik:GridViewDataColumn DataMemberBinding="{Binding AlarmClass, Mode=OneWay}"
Header="Alarm Class"
Width="150" />
<telerik:GridViewDataColumn DataMemberBinding="{Binding Notes, Mode=OneWay}"
Header="Notes"
Width="*" />
</telerik:RadGridView.Columns>
</telerik:RadGridView>
<cs:ProgressControl FontSize="14"
FontWeight="Bold"
Grid.Column="0"
Grid.Row="1"
Height="55"
Margin="0,5"
x:Name="HotListProgressCtrl"
TabIndex="11"
TimeOfDayMode="{Binding Path=TimeOfDayMode, RelativeSource={RelativeSource AncestorType={x:Type cs:Searcher}}}"
Visibility="Collapsed" />
</Grid>
</TabItem>
<TabItem Background="{DynamicResource TabHeaderBackground}"
FontSize="16"
FontWeight="Bold"
Foreground="{DynamicResource TabHeaderForeground}"
Header="Reads & Alarms:"
IsSelected="True"
Name="ReadsTabItem">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<telerik:RadGridView AutoExpandGroups="True"
AutoGenerateColumns="False"
CanUserDeleteRows="False"
CanUserFreezeColumns="False"
CanUserInsertRows="False"
CanUserResizeColumns="True"
CanUserSortColumns="True"
EnableColumnVirtualization="True"
EnableRowVirtualization="True"
FontSize="14"
FontWeight="Bold"
IsReadOnly="True"
Name="ReadsGrid"
RowDetailsTemplate="{StaticResource ReadRowDetailsTemplate}"
RowStyleSelector="{StaticResource StyleSelector}"
SelectionChanged="ReadsGrid_SelectionChanged"
SelectionUnit="FullRow"
ScrollViewer.CanContentScroll="True"
ScrollViewer.HorizontalScrollBarVisibility="Auto"
ScrollViewer.VerticalScrollBarVisibility="Auto"
ShowGroupFooters="True"
TabIndex="12"
ToolTip="Matching Reads">
<telerik:RadGridView.Columns>
<cs:CustomGridViewToggleRowDetailsColumn IsEnabled="False"
IsFilterable="False"
IsGroupable="False"
ToggleButtonVisibility="{Binding Path=HasAlarms, Converter={StaticResource BoolToVisibility}}" />
<telerik:GridViewDataColumn DataMemberBinding="{Binding Plate, Mode=OneWay}"
Header="Plate"
Width="*" />
<telerik:GridViewDataColumn DataMemberBinding="{Binding State, Mode=OneWay}"
Header="State"
Width="75" />
<telerik:GridViewDataColumn DataMemberBinding="{Binding TimeStamp, Mode=OneWay, Converter={StaticResource DateConverter}}"
Header="Date & Time"
Width="150" />
<telerik:GridViewDataColumn DataMemberBinding="{Binding Latitude, Converter={StaticResource CoordConverter}, ConverterParameter=NS}"
Header="Latitude"
Width="150" />
<telerik:GridViewDataColumn DataMemberBinding="{Binding Longitude, Converter={StaticResource CoordConverter}, ConverterParameter=EW}"
Header="Longitude"
Width="150" />
</telerik:RadGridView.Columns>
</telerik:RadGridView>
<cs:ProgressControl FontSize="14"
FontWeight="Bold"
Grid.Row="1"
Height="55"
Margin="0,5"
x:Name="ProgressCtrl"
TabIndex="13"
TimeOfDayMode="{Binding Path=TimeOfDayMode, RelativeSource={RelativeSource AncestorType={x:Type cs:Searcher}}}"
Visibility="Collapsed" />
</Grid>
</TabItem>
</TabControl>
<GridSplitter Background="{DynamicResource SeparatorColor}"
Grid.Row="1"
Height="10"
HorizontalAlignment="Stretch"
Margin="0,5"
VerticalAlignment="Top" />
<Grid Grid.Column="1"
Grid.RowSpan="2">
<Grid.RowDefinitions>
<RowDefinition Height="55" />
<RowDefinition Height="55" />
<RowDefinition Height="55" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="55" />
<RowDefinition Height="55" />
</Grid.RowDefinitions>
<Button Background="{DynamicResource ButtonBackground}"
Click="SearchButton_Click"
Content="Search"
FontSize="16"
FontWeight="Bold"
Foreground="{DynamicResource ButtonForeground}"
Grid.Row="0"
IsDefault="True"
Margin="5"
Name="SearchButton"
TabIndex="14" />
<Button Background="{DynamicResource ButtonBackground}"
Click="ClearButton_Click"
Content="Clear"
FontSize="16"
FontWeight="Bold"
Foreground="{DynamicResource ButtonForeground}"
Grid.Row="1"
Margin="5"
Name="ClearButton"
TabIndex="15" />
<Button Background="{DynamicResource ButtonBackground}"
Click="SaveCriteriaButton_Click"
FontSize="16"
FontWeight="Bold"
Grid.Row="2"
Foreground="{DynamicResource ButtonForeground}"
Margin="5"
Name="SaveCriteriaButton"
TabIndex="16"
Visibility="Visible">
<Button.Content>
<TextBlock Text="Save Report"
TextAlignment="Center"
TextWrapping="Wrap" />
</Button.Content>
</Button>
<TextBlock FontSize="14"
FontWeight="Bold"
Foreground="{DynamicResource TextForeground}"
Grid.Row="4"
Margin="5"
Text="Number of Matches:"
TextAlignment="Center"
TextWrapping="Wrap" />
<TextBlock FontSize="14"
FontWeight="Bold"
Foreground="{DynamicResource TextForeground}"
Grid.Row="5"
Margin="5"
Text="Hot List Entries:"
TextAlignment="Center"
TextWrapping="Wrap" />
<TextBlock FontSize="14"
FontWeight="Bold"
Foreground="{DynamicResource TextForeground}"
Grid.Row="6"
Margin="5,0,5,10"
Text="{Binding Converter={StaticResource LongConverter}, ConverterParameter='#,##0', Path=NoHotListEntries, RelativeSource={RelativeSource AncestorType={x:Type cs:Searcher}}}"
TextAlignment="Center"
TextWrapping="Wrap" />
<TextBlock FontSize="14"
FontWeight="Bold"
Foreground="{DynamicResource TextForeground}"
Grid.Row="7"
Margin="5"
Text="Reads:"
TextAlignment="Center"
TextWrapping="Wrap" />
<TextBlock FontSize="14"
FontWeight="Bold"
Foreground="{DynamicResource TextForeground}"
Grid.Row="8"
Margin="5,0,5,10"
Text="{Binding Converter={StaticResource LongConverter}, ConverterParameter='#,##0', Path=NoReads, RelativeSource={RelativeSource AncestorType={x:Type cs:Searcher}}}"
TextAlignment="Center"
TextWrapping="Wrap" />
<Button Background="{DynamicResource ButtonBackground}"
Click="ExportButton_Click"
Content="Export"
FontSize="16"
FontWeight="Bold"
Foreground="{DynamicResource ButtonForeground}"
Grid.Row="10"
Margin="5"
Name="ExportButton"
TabIndex="17" />
<Button Background="{DynamicResource ButtonBackground}"
Click="CloseButtonClicked"
Content="Close"
FontSize="20"
FontWeight="Bold"
Foreground="{DynamicResource ButtonForeground}"
Grid.Row="11"
HorizontalAlignment="Right"
Margin="5"
Name="CloseButton"
TabIndex="18"
Width="100" />
</Grid>
<Canvas Grid.Column="0"
Grid.ColumnSpan="2"
Grid.Row="0"
Grid.RowSpan="4"
Name="KeyboardPopupCanvas">
<cs:KeyboardPopup x:Name="KeyboardPopup"
TimeOfDayMode="{Binding Path=TimeOfDayMode, RelativeSource={RelativeSource AncestorType={x:Type cs:Searcher}}}"
Title="Keyboard"
Visibility="Collapsed" />
</Canvas>
</Grid>
Thanks for your help
Tony
Just so that people who view this question later will know, the solution I went with was to rearrange the fields on the form so that the field I wanted to have the focus initially was the first field on the form. WPF automatically gives the focus to the control with the lowest TabIndex. Which is why my control was losing the focus after I put it there in the Loaded event handler.
I suppose that if I didn't have any TabIndex field setters in the Xaml that this would never have happened. Live and learn.

Last Grid Column Not Auto Resizing With Grid

I'm having a problem with my TextBoxs not "Auto" resizing. I'm trying to create a form that behaves and looks like the Properties Editor in Visual Studio. What appears to be happening is that the third column is not expanding to fill all of the available remaining space in the grid. Image below is how my form looks on startup.
The width of the textboxs is determined by the MinWidth setting on the third ColumnDefinition statement. Also, the Width is set to "*". With any other setting, the resizing done with the GridSplitter doesn't work correctly.
<StackPanel Orientation="Vertical" VerticalAlignment="Top" x:Name="Stacker" Grid.IsSharedSizeScope="True">
<Expander x:Name="Expand" IsExpanded="True" Header="This is a test of a Second Panel" Width="{Binding Width, ElementName=Stacker}">
<Grid x:Name="EditGrid1" Margin="3" >
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" MinWidth="50" SharedSizeGroup="SharedSize1" />
<ColumnDefinition Width="Auto" SharedSizeGroup="SharedSize2" />
<ColumnDefinition Width="*" MinWidth="50" x:Name="ValueCol" />
</Grid.ColumnDefinitions>
<GridSplitter Grid.Column="1" x:Name="ToolBoxSplitter1" Grid.Row="1" Grid.RowSpan="6" Panel.ZIndex="1" HorizontalAlignment="Stretch" ResizeBehavior="PreviousAndNext" Width="3"/>
<TextBlock MaxHeight="40" Grid.Column="0" Grid.Row="1" Text="{x:Static lex:DoSomeThingView.Name}" />
<TextBlock MaxHeight="40" Grid.Column="0" Grid.Row="2" Text="{x:Static lex:DoSomeThingView.Address}" />
<TextBlock MaxHeight="40" Grid.Column="0" Grid.Row="3" Text="{x:Static lex:DoSomeThingView.Zip}" />
<TextBlock MaxHeight="40" Grid.Column="0" Grid.Row="4" Text="{x:Static lex:DoSomeThingView.NumberOfDoors}" TextTrimming="CharacterEllipsis" Grid.IsSharedSizeScope="True" />
<TextBlock MaxHeight="40" Grid.Column="0" Grid.Row="5" Text="{x:Static lex:DoSomeThingView.DoubleNumber}" />
<TextBox Grid.Column="2" Grid.Row="1" x:Name="UserName1" MaxHeight="50" TextWrapping="Wrap"
VerticalScrollBarVisibility="Auto" SpellCheck.IsEnabled="True" />
<TextBox Grid.Column="2" Grid.Row="2" x:Name="Address1" />
<TextBox Grid.Column="2" Grid.Row="3" x:Name="Zip1" />
<TextBox Grid.Column="2" Grid.Row="4" x:Name="NumberOfDoors1" />
<TextBox Grid.Column="2" Grid.Row="5" x:Name="DoubleNumber1" />
</Grid>
</Expander>
</StackPanel>
Any suggestions on how to correct this?
Have a check once again of any style being set globally because your layout worked perfectly fine with me.
try overriding your textbox style by a local resource
<StackPanel.Resources>
<Style TargetType="{x:Type TextBox}"/>
</StackPanel.Resources>

Resources