我有绑定到文本框文本属性的MachineViewModel的EraNumber属性,以及绑定到datagrid的MachineViewModel的CollectionViewSource。每当更改文本框的值时,绑定到datagrid的集合视图源的每个Item都会更改为文本框的值。
>
<UserControl.DataContext>
<Vm:MachineViewModel/>
</UserControl.DataContext>
<Grid x:Name="vehiclesGrid" Width="390" ShowGridLines="false" >
<Grid.RowDefinitions>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Label x:Name="lblVehicleEra" Content="Era Number"/>
<TextBox x:Name="txtVehicleEra" Grid.Column="2" PreviewTextInput="numbersOnly" Text="{Binding Era, NotifyOnTargetUpdated=True, NotifyOnValidationError=True, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" Style="{StaticResource TextError}" messenger:CommandBehavior.RoutedEventName="LostFocus" messenger:CommandBehavior.TheCommandToRun="{Binding EraNumberChangedCommand}" />
<DataGrid x:Name="dataDisplayReport"
EnableColumnVirtualization="True"
EnableRowVirtualization="True"
HorizontalScrollBarVisibility="Auto"
HorizontalAlignment="Stretch"
Grid.ColumnSpan="2" Width="Auto"
AutoGenerateColumns="True"
ItemsSource="{Binding Source={StaticResource cvsMachines}}"
CanUserAddRows="False"
>
<DataGrid.ContextMenu>
<ContextMenu>
<MenuItem Header="Update" Command="{Binding UpdateMachine}"/>
</ContextMenu>
</DataGrid.ContextMenu>
</DataGrid>
1条答案
按热度按时间62lalag41#
将
BindingMode
设置为OneWay
应该可以。这里有更多关于绑定模式的信息。