【发布时间】:2016-12-21 11:05:31
【问题描述】:
我目前正在开发 WPF 表单并尝试应用 MVVM 模式。 我有一个数据网格、两个编辑控件和一个按钮。简化后的代码如下:
<syncfusion:SfDataGrid Grid.Row="1" Name="TempGrid" ItemsSource="{Binding TempProfile}" SelectedItem="{Binding SelectedTempSetpoint}">
</syncfusion:SfDataGrid>
<syncfusion:TimeSpanEdit Format="hh:mm" Value="{Binding SelectedTempSetpoint.Time, Mode=OneWay}" />
<syncfusion:UpDown Value="{Binding SelectedTempSetpoint.Value, Mode=OneWay}" >
<Button Content="Add" Command="{Binding AddTempSetpointCommand}">
我使用 OneWay-Binding 来更新 Edit-Control 的内容,每次或 Datagrid 中所选元素的值发生变化。但是我希望能够更改编辑控件中的值并使用该值将另一个元素添加到数据网格。为此,我想使用按钮的命令属性(以及 ViewModel 中的 DelegateCommand)。 通常,我会将编辑控件的值绑定到我的 VM 中的属性,但是如果 SelectedElement 发生更改,我将失去它们更新的功能。 这样做的正确方法是什么?使用单独的属性并在 VM 中更新它们?或者有没有办法将控件绑定到多个属性?
【问题讨论】: