我有一个包含五列的数据网格:名字,姓氏,用户,密码和角色。我只使用CellTemplate和CellEditingTemplate使用密码和角色。问题是,当我在属于名为Password或Role的列之一的单元格上进入编辑模式后,除了包含相应单元格的行之外,我无法进入其他行的编辑模式。 我不知道该怎么做了,我已经失去了两天。
这是我的代码:
<DataGrid ItemsSource="{Binding Elements}"
AutoGenerateColumns="False"
CanUserAddRows="True"
CanUserDeleteRows="True"
IsReadOnly="False"
Style="{StaticResource DataGridStyle}"
CellStyle="{StaticResource LeftCellStyle}"
RowHeight="30">
<DataGrid.Resources>
<Style TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="HorizontalContentAlignment"
Value="Center" />
</Style>
</DataGrid.Resources>
<DataGrid.RowValidationRules>
<continut:UtilizatorRowValidationRule ValidationStep="UpdatedValue"></continut:UtilizatorRowValidationRule>
</DataGrid.RowValidationRules>
<DataGrid.RowStyle>
<Style TargetType="{x:Type DataGridRow}">
<Style.Triggers>
<Trigger Property="IsSelected"
Value="True">
<Setter Property="Background"
Value="CornflowerBlue" />
</Trigger>
</Style.Triggers>
</Style>
</DataGrid.RowStyle>
<DataGrid.Columns>
<!--First Name-->
<DataGridTemplateColumn Width="*"
Header="FirstNume"
CellStyle="{StaticResource LeftCellStyle}">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding FirstName}"></TextBlock>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<!--Last Name-->
<DataGridTemplateColumn Width="*"
Header="LastName"
CellStyle="{StaticResource LeftCellStyle}">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding LastName}"></TextBlock>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<!--User-->
<DataGridTemplateColumn Width="*"
Header="User"
CellStyle="{StaticResource LeftCellStyle}">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding UserName}"></TextBlock>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<!--Password-->
<DataGridTemplateColumn Width="*"
Header="Password"
CellStyle="{StaticResource CenterCellStyle}">
<DataGridTemplateColumn.HeaderStyle>
<Style TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="HorizontalContentAlignment"
Value="Center" />
</Style>
</DataGridTemplateColumn.HeaderStyle>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="Click here to modify."></TextBlock>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<PasswordBox Name="PasswordBoxPass"
PasswordChanged="PasswordBoxPass_PasswordChanged"
Width="300"
Height="25" />
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
</DataGridTemplateColumn>
<!--Role-->
<DataGridTemplateColumn Header="Role"
Width="*"
CellStyle="{StaticResource CenterCellStyle}">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="Select the role."></TextBlock>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<ComboBox Grid.Row="2"
Grid.Column="2"
IsEditable="False"
ItemsSource="{Binding DataContext.RoleVM, RelativeSource={RelativeSource AncestorType=DataGrid}}"
SelectedItem="{Binding ChosenRole, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Height="25">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Description}"
Width="300"
VerticalAlignment="Center" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
我应用的某些样式是否可能会导致此行为?