我的xaml文件中有以下代码:
<WrapPanel Grid.Row="0" HorizontalAlignment="Center" Margin="10">
<Label Content="Azonosító:"/>
<TextBox x:Name="txtId" Width="80" IsEnabled="False" Text="{Binding Path=SelectedStudent.Id, Mode=TwoWay}"/>
<Label Content="Név:"/>
<TextBox x:Name="txtName" Width="100" Text="{Binding Path=SelectedStudent.Name, Mode=TwoWay}"/>
<Label Content="Cím:"/>
<TextBox x:Name="txtAddress" Width="150" Text="{Binding Path=SelectedStudent.Address, Mode=TwoWay}"/>
<Label Content="Kar:"/>
<TextBox x:Name="txtFaculty" Width="50" Text="{Binding Path=SelectedStudent.Faculty, Mode=TwoWay}"/>
</WrapPanel>
...
<DataGrid x:Name="dgdStudents" Grid.Row="1" Background="White" BorderBrush="LightGray" CanUserAddRows="False"
CanUserDeleteRows="False" CanUserReorderColumns="False" Cursor="Hand"
ItemsSource="{Binding Students}" AutoGenerateColumns="False" IsReadOnly="True" SelectionMode="Single"
SelectionUnit="FullRow" SelectedItem="{Binding SelectedStudent, Mode=OneWayToSource}">
正如您所看到的,我在WrapPanel中将SelectedStudent与TwoWay模式绑定,并在DataGrid中绑定OneWayToSource模式。但是,每当我在数据网格中选择一行并修改文本框中的值时,所选行也会根据修改而更改。为什么呢?