2 回答
TA贡献1906条经验 获得超10个赞
忘记尝试在“纯 XAML”中应用程序实现这样的逻辑,而是在视图模型中实现它。XAML 是一种标记语言。
A1should set 的 setter 和 should set的setter B1,例如:A2B2
public class ViewModel : INotifyPropertyChanged
{
private string _a1;
public string A1
{
get { return _a1; }
set { _a1 = value; NotifyPropertyChanged(); B1 = value; }
}
private string _b1;
public string B1
{
get { return _b1; }
set { _b1 = value; NotifyPropertyChanged(); }
}
//+the same for A2 and B2
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
XAML:
保存数据只需从B1和B2属性中获取值,无论它们是如何设置的。
TA贡献1775条经验 获得超8个赞
这可以通过TwoWay绑定来解决,但是TextBoxLostFocus默认是更新的,UpdateSourceTrigger也需要修改,代码如下:
<!-- Data A -->
<TextBox Name="txtDataA1" Text="{Binding dataStore.A1, UpdateSourceTrigger=PropertyChanged}"/>
<TextBox Name="txtDataA2" Text="{Binding dataStore.A2, UpdateSourceTrigger=PropertyChanged}"/>
<!-- Data B -->
<TextBox Name="txtDataB1" Text="{Binding ElementName=txtDataA1, Path=Text, Mode=TwoWay}" />
<TextBox Name="txtDataB2" Text="{Binding ElementName=txtDataA2, Path=Text, Mode=TwoWay}" />
- 2 回答
- 0 关注
- 237 浏览
添加回答
举报
