0

I have a data template that contains a grid. I would like to make the selected row of the grid larger (height-wise) when the user selects the row. Each cell in the row contains a rectangle for styling purposes and a textbox for data. I have the following that resizes the row when the user clicks on the rectangle, but not when they click inside the text box (which is where they are likely to click). How can I make the row resize when the user clicks in the textbox?

 <!-- Mapping Rules Template --> <DataTemplate x:Key="MappingRuleTemplate"> <Grid Margin="0"> <Grid.RowDefinitions> <RowDefinition Height="26"/> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="20" /> <ColumnDefinition Width="150"/> <ColumnDefinition Width="75"/> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions> <!-- Shading --> <Rectangle Grid.Column="0" Style="{StaticResource TableRowShade}" Margin="0" /> <Rectangle Grid.Column="1" Style="{StaticResource TableRowShadeALT}" Margin="0" /> <Rectangle Grid.Column="2" Style="{StaticResource TableRowShade}" Margin="0" /> <Rectangle Grid.Column="3" Style="{StaticResource TableRowShadeALT}" Margin="0" HorizontalAlignment="Stretch" /> <!-- End Shading --> <Button Name="DeleteButton" Grid.Column="0" Style="{StaticResource ImageButton}" Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type StackPanel}}, Path=DataContext.DeleteRuleButtonClickedCommand}" ToolTip="Delete this mapping rule" local:AttachedImage.Image="{StaticResource CancelImageSource}" > <Button.CommandParameter> <MultiBinding Converter="{StaticResource DeleteButtonConverter}"> <Binding ElementName="TableName" Path="Text" /> <Binding ElementName="FieldNumber" Path="Text" /> </MultiBinding> </Button.CommandParameter> </Button> <TextBox Name="TableName" Grid.Column="1" VerticalAlignment="Center" Margin="4,0,4,5" Height="20" Text="{Binding TableName, Mode=TwoWay, NotifyOnSourceUpdated=True, UpdateSourceTrigger=PropertyChanged}" FocusManager.IsFocusScope="True" Style="{StaticResource NewRecordsStyle}" HorizontalAlignment="Stretch" /> <TextBox Name="FieldNumber" Grid.Column="2" VerticalAlignment="Center" Margin="4,0,4,5" Height="20" Width="50" Text="{Binding FieldNumber, NotifyOnSourceUpdated=True, UpdateSourceTrigger=PropertyChanged}" TextAlignment="Center" Style="{StaticResource NewRecordsStyle}" HorizontalAlignment="Stretch" /> <TextBox Name="DynamicSQL" Grid.Column="3" VerticalAlignment="Center" Margin="4,0,4,5" Text="{Binding DynamicSQL, NotifyOnSourceUpdated=True, UpdateSourceTrigger=PropertyChanged}" Style="{StaticResource NewRecordsStyle}" HorizontalAlignment="Stretch" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden" Height="20" Width="303" /> </Grid> </DataTemplate> <DataTemplate x:Key="MappingRuleSelectedTemplate"> <Grid Margin="0"> <Grid.RowDefinitions> <RowDefinition Height="110"/> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="20" /> <ColumnDefinition Width="150" Style="{StaticResource TableRowShadeALT}"/> <ColumnDefinition Width="75"/> <ColumnDefinition Width="*" Style="{StaticResource TableRowShadeALT}"/> </Grid.ColumnDefinitions> <!-- Shading --> <Rectangle Grid.Column="0" Style="{StaticResource TableRowShade}" Margin="0" /> <Rectangle Grid.Column="1" Style="{StaticResource TableRowShadeALT}" Margin="0" /> <Rectangle Grid.Column="2" Style="{StaticResource TableRowShade}" Margin="0" /> <Rectangle Grid.Column="3" Style="{StaticResource TableRowShadeALT}" Margin="0" HorizontalAlignment="Stretch" Height="110" /> <!-- End Shading --> <Button Name="DeleteButton" Grid.Column="0" Style="{StaticResource ImageButton}" Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type StackPanel}}, Path=DataContext.DeleteRuleButtonClickedCommand}" ToolTip="Delete this mapping rule" local:AttachedImage.Image="{StaticResource CancelImageSource}" > <Button.CommandParameter> <MultiBinding Converter="{StaticResource DeleteButtonConverter}"> <Binding ElementName="TableName" Path="Text" /> <Binding ElementName="FieldNumber" Path="Text" /> </MultiBinding> </Button.CommandParameter> </Button> <TextBox Name="TableName" Grid.Column="1" VerticalAlignment="Center" Margin="4,0,4,5" Height="20" Text="{Binding TableName, Mode=TwoWay, NotifyOnSourceUpdated=True, UpdateSourceTrigger=PropertyChanged}" FocusManager.IsFocusScope="True" Style="{StaticResource NewRecordsStyle}" HorizontalAlignment="Stretch" /> <TextBox Name="FieldNumber" Grid.Column="2" VerticalAlignment="Center" Margin="4,0,4,5" Height="20" Width="50" Text="{Binding FieldNumber, NotifyOnSourceUpdated=True, UpdateSourceTrigger=PropertyChanged}" TextAlignment="Center" Style="{StaticResource NewRecordsStyle}" HorizontalAlignment="Stretch" /> <TextBox Name="DynamicSQL" Grid.Column="3" VerticalAlignment="Center" Margin="4,0,4,5" Text="{Binding DynamicSQL, NotifyOnSourceUpdated=True, UpdateSourceTrigger=PropertyChanged}" Style="{StaticResource NewRecordsStyle}" HorizontalAlignment="Stretch" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" Height="100" Width="303"/> </Grid> </DataTemplate> <Style TargetType="{x:Type ListBoxItem}" x:Key="ContainerStyle"> <Setter Property="Padding" Value="0"/> <Setter Property="BorderThickness" Value="0"/> <Setter Property="ContentTemplate" Value="{StaticResource MappingRuleTemplate}" /> <Style.Triggers> <Trigger Property="IsSelected" Value="True"> <Setter Property="ContentTemplate" Value="{StaticResource MappingRuleSelectedTemplate}" /> </Trigger> </Style.Triggers> </Style> ..... <ListBox Name="QuarterlyCompanyFieldMappingControl" ItemContainerStyle="{StaticResource ContainerStyle}" ItemsSource="{Binding QuarterlyCompanyMappings.FieldMappingCollection, NotifyOnSourceUpdated=True, UpdateSourceTrigger=PropertyChanged}" ScrollViewer.HorizontalScrollBarVisibility="Disabled" AlternationCount="2" BorderThickness="0" Padding="0"> 
2
  • You know... I actually started to copy your code example into a new project to test your problem, but you have so many references to things that are not in your example that cause errors, that I just gave up. If you want help, then you need to provide the right code for use to test. Remove all references that would break your example and re-upload the complete, but concise working example of your code that still exhibits the same problem if you want help. I'm pretty sure that you just need to set the UIElement.IsKeyboardFocusWithin property. Commented Mar 19, 2014 at 13:36
  • Thanks for the effort and your tip about IsKeyboardFocusWithin got me to the following posting that solved my problem by adding the OnChildGotFocus to each TextBox. stackoverflow.com/questions/3022300/… Commented Mar 19, 2014 at 14:45

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.