我在WPF中有一個ContentControl,它包含一些輸入控件,如TextBoxes和ComboBoxes。 這些控件中的每一個都是數據綁定到ViewModel中的給定屬性,其中UpdateSourceTrigger=Explicit
。迭代VisualTreeHelper.GetChild()並在包含數據綁定的控件上調用UpdateSource
當我點擊了一些「提交」按鈕,我要穿越的FormularioPaciente
有綁定的每一個孩子,並呼籲UpdateSource
:
private void btnSalvarEditarPaciente_Click(object sender, System.Windows.RoutedEventArgs e) {
foreach (var childControl in LogicalTreeHelper.GetChildren(FormularioPaciente)) {
// what should I do now?
// I would really like to "auto-find" everything that should be updated...
}
}
http://stackoverflow.com/questions/3586870/retrieve-all-data-bindings-from-wpf-window/3587263#3587263這個答案可以幫助你找到所有的綁定 – Nitin
@nit我認爲這是一個確切的重複,但IT不是,因爲它告訴如何找到綁定作爲'BindingBase',但不告訴如何調用'BindingExpression.UpdateSource' ... – heltonbiker
嗯..我已經更新了你的答案。 。希望它可以幫助 – Nitin