在下面的窗口中,现有报告组合绑定到一个可观察的报告对象集合。我有一个currentReport
绑定到组合的 SelectedValue 属性 OneWay 的 reportObject 属性。但是,这在 XAML 中绑定时不起作用。
SelectedValue="{Binding currentReport, Mode=OneWay}"
undo()
TwoWay 绑定得很好,但是如果不向 reportObject 类编写方法,我就不能这样做。我将 currentReport 的属性绑定到各种文本框以进行编辑。我想绑定 OneWay,这样源就不会改变。currentReport 的所有属性都绑定到相应的文本框,因此当我在 SQL [Save] 中更新表时,它将从该对象中提取数据,该对象的数据是最新的。
<TextBox Text="{Binding currentReport.reportName, Mode=TwoWay}"
从 currentReport 绑定到文本框的所有属性也都可以正常工作。唯一的问题是从 SelectedValue 到 currentReport 对象的 OneWay 绑定。有谁知道如何让它发挥作用?我看到有一个错误,但我看到的帖子是 2009 年的。
对不起黄色。不是我的主意。=)
编辑:添加此 XAML 以防万一。
<ComboBox ItemsSource="{Binding reportsCollection}" SelectionChanged="cboReports_SelectionChanged"
DisplayMemberPath="displayName"
SelectedValue="{Binding currentReport, Mode=TwoWay}"
x:Name="cboReports" Width="342" Height="40" VerticalAlignment="Center"/>