【发布时间】:2018-02-09 17:54:38
【问题描述】:
我有一个绑定在 ObservableCollection 上的 ListView。
<ListView Grid.Column="0" Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" BorderThickness="0" Margin="5" Name="CustomerListView" ItemsSource="{Binding Customers}" SelectedItem="{Binding Path=CurrentCustomer, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
<ListView.ItemTemplate>
<DataTemplate>
<WrapPanel>
<TextBlock Text="{Binding FirstName}"/>
<TextBlock Margin="5,0,0,0" Text="{Binding LastName}"/>
</WrapPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
在同一个视图中,我有一些用于编辑 CurrentCustomer 的文本框。我还有一个保存按钮。如果单击此按钮,则应保存 CurrentCustomer 的修改。如果按下“取消”按钮,则应放弃修改。
<TextBox Name="CustomerSalutationTextBox" Grid.Column="1" Grid.Row="0" Height="20px" Margin="5" Text="{Binding Path=CurrentCustomer.Salutation, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
问题是,如果我对 currentCusomer 进行一些更改,它们会立即生效。
你有解决办法吗?
【问题讨论】:
-
请用英文发表问题
-
我添加了英语 cmets ;-)
-
最好删除德语文本,因为它在阅读时会混淆。
标签: c# asp.net button save selecteditem