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 關注
- 181 瀏覽
添加回答
舉報