我的界面中有这些文本框:
其中Total和Change框是只读的.我的问题是,当用户输入付款时,如何执行计算变更的方法?
有界付款文本框是这样的:
private decimal _cartPayment;
public decimal CartPayment {
get { return _cartPayment; }
set {
_cartPayment = value;
//this.NotifyPropertyChanged("CartPayment");
}
}
Run Code Online (Sandbox Code Playgroud)
我的XAML如下:
<TextBox Text="{Binding Path=CartPayment, Mode=TwoWay}" />
Run Code Online (Sandbox Code Playgroud)
我的ViewModel已INotifyPropertyChanged
实现,但我不知道如何从这里开始
这是一个MVVM方法,它不会破解任何属性的get/set:
<TextBox Text="{Binding Path=CartPayment, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="TextChanged">
<i:InvokeCommandAction Command="{Binding ComputeNewPriceCommand}" />
</i:EventTrigger>
<i:Interaction.Triggers>
</TextBox>
Run Code Online (Sandbox Code Playgroud)
xmlns:i
作为System.Windows.Interactivity
xaml 中的命名空间
ComputeNewPriceCommand是指向重新计算方法的任何类型的ICommand.
您可以利用UpdateSourceTrigger.你可以修改你的代码
<TextBox Text="{Binding Path=CartPayment, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
Run Code Online (Sandbox Code Playgroud)
和你的财产一样
private decimal _cartPayment;
public decimal CartPayment
{
get { return _cartPayment; }
set
{
_cartPayment = value;
// call your required
// method here
this.NotifyPropertyChanged("CartPayment");
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
6405 次 |
最近记录: |