我有一个包含网格的数据模板。当用户选择行时,我想使网格的选定行更大(高度方向)。该行中的每个单元格都包含一个用于样式设置的矩形和一个用于数据的文本框。我有以下内容,当用户单击矩形时调整行的大小,但是当他们单击文本框内部时(这是他们可能单击的位置)时,不会调整行的大小。如何在用户单击文本框时调整行大小?
<!-- 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">