private void RestoreOriginalBinding(TextBox element) { var originalBinding = GetOriginalBinding(element); var text = element.Text; var deferredValue = GetDeferredValue(element); BindingOperations.ClearBinding(element, DeferredValueProperty); BindingOperations.SetBinding(element, TextBox.TextProperty, originalBinding); SetDeferredValue(element, deferredValue); element.Text = text; //var expression = BindingOperations.GetBindingExpression(element, TextBox.TextProperty); //expression?.UpdateTarget(); if (!ChangesAvailable) { SetDeferredValue(element, null); } }
private void btnDelete_Inv_Click(object sender, RoutedEventArgs e) { action = ActionState.Delete; string tempColor = colorTextBox.Text.ToString(); string tempMake = makeTextBox.Text.ToString(); btnNew_Inv.IsEnabled = false; btnEdit_Inv.IsEnabled = false; btnDelete_Inv.IsEnabled = false; btnSave_Inv.IsEnabled = true; btnCancel_Inv.IsEnabled = true; btnNext_Inv.IsEnabled = false; btnPrev_Inv.IsEnabled = false; inventoryDataGrid.IsEnabled = false; carIdTextBox.IsEnabled = true; colorTextBox.IsEnabled = true; makeTextBox.IsEnabled = true; BindingOperations.ClearBinding(colorTextBox, TextBox.TextProperty); BindingOperations.ClearBinding(makeTextBox, TextBox.TextProperty); colorTextBox.Text = tempColor; makeTextBox.Text = tempMake; }
private void btnDelete2_Click(object sender, RoutedEventArgs e) { action = ActionState.Delete; string tempCustomer = cmbCustomers.Text.ToString(); string tempInventory = cmbInventory.Text.ToString(); btnNew2.IsEnabled = false; btnEdit2.IsEnabled = false; btnDelete2.IsEnabled = false; btnSave2.IsEnabled = true; btnCancel2.IsEnabled = true; orderDataGrid.IsEnabled = false; btnPrevious2.IsEnabled = false; btnNext2.IsEnabled = false; BindingOperations.ClearBinding(cmbCustomers, ComboBox.TextProperty); BindingOperations.ClearBinding(cmbInventory, ComboBox.TextProperty); cmbCustomers.Text = tempCustomer; cmbInventory.Text = tempInventory; }
private void btnDelete2_Click(object sender, RoutedEventArgs e) { //nu sunt sigura ca e ok action = ActionState.Delete; string tempcustId = custIdTextBox.Text.ToString(); string tempcarId = carIdTextBox.Text.ToString(); btnNew2.IsEnabled = false; btnEdit2.IsEnabled = false; btnDelete2.IsEnabled = false; btnSave2.IsEnabled = true; btnCancel2.IsEnabled = true; ordersDataGrid.IsEnabled = false; btnPrev2.IsEnabled = false; btnNext2.IsEnabled = false; custIdTextBox.IsEnabled = false; carIdTextBox.IsEnabled = false; BindingOperations.ClearBinding(custIdTextBox, TextBox.TextProperty); BindingOperations.ClearBinding(carIdTextBox, TextBox.TextProperty); custIdTextBox.Text = tempcustId; carIdTextBox.Text = tempcarId; }
private void InitializeVisualElementsContainer() { this._expander.Click -= this.ExpanderClick; this._clickButton.Click -= this.ButtonClick; this._listBox.SelectionChanged -= this.ListBoxSelectionChanged; this._listBox.PreviewMouseLeftButtonDown -= this.ListBoxPreviewMouseLeftButtonDown; this._popup.Opened -= this.PopupOpened; this._popup.Closed -= this.PopupClosed; this._expander.Click += this.ExpanderClick; this._clickButton.Click += this.ButtonClick; this._listBox.SelectionChanged += this.ListBoxSelectionChanged; this._listBox.PreviewMouseLeftButtonDown += this.ListBoxPreviewMouseLeftButtonDown; this._popup.Opened += this.PopupOpened; this._popup.Closed += this.PopupClosed; BindingOperations.ClearBinding(this._listBox, ItemsSourceProperty); this._listBox.SetBinding(ItemsSourceProperty, new Binding(ItemsSourceProperty.Name) { Mode = BindingMode.OneWay, RelativeSource = RelativeSource.TemplatedParent }); }
private void btnCancel2_Click(object sender, RoutedEventArgs e) { action = ActionState.Nothing; btnNew2.IsEnabled = true; btnEdit2.IsEnabled = true; btnSave2.IsEnabled = false; btnCancel2.IsEnabled = false; btnPrev2.IsEnabled = true; btnNext2.IsEnabled = true; custIdTextBox.IsEnabled = false; firstNameTextBox.IsEnabled = false; lastNameTextBox.IsEnabled = false; carIdTextBox.IsEnabled = false; colorTextBox.IsEnabled = false; makeTextBox.IsEnabled = false; //firstNameTextBox.SetBinding(TextBox.TextProperty, firstNameTextBoxBinding); //txtPhoneNumber.SetBinding(TextBox.TextProperty, txtPhoneNumberBinding); //txtPhoneNumber.SetBinding(TextBox.TextProperty, txtPhoneNumberBinding); BindingOperations.ClearBinding(firstNameTextBox, TextBox.TextProperty); BindingOperations.ClearBinding(lastNameTextBox, TextBox.TextProperty); BindingOperations.ClearBinding(colorTextBox, TextBox.TextProperty); BindingOperations.ClearBinding(makeTextBox, TextBox.TextProperty); }
private void btnEdit2_Click(object sender, RoutedEventArgs e) { action = ActionState.Edit; string tempCustomers = cmbCustomers.Text.ToString(); string tempInventory = cmbInventory.Text.ToString(); btnNew2.IsEnabled = false; btnEdit2.IsEnabled = false; btnDelete2.IsEnabled = false; btnSave2.IsEnabled = true; btnCancel2.IsEnabled = true; ordersDataGrid.IsEnabled = false; btnPrev2.IsEnabled = false; btnNext2.IsEnabled = false; cmbCustomers.IsEnabled = true; cmbInventory.IsEnabled = true; BindingOperations.ClearBinding(cmbCustomers, TextBox.TextProperty); BindingOperations.ClearBinding(cmbInventory, TextBox.TextProperty); cmbCustomers.Text = tempCustomers; cmbInventory.Text = tempInventory; Keyboard.Focus(cmbCustomers); }
private void btnDelete_Click(object sender, RoutedEventArgs e) { action = ActionState.Delete; string tempFirstName = firstNameTextBox.Text.ToString(); string tempLastName = lastNameTextBox.Text.ToString(); btnNew.IsEnabled = false; btnEdit.IsEnabled = false; btnDelete.IsEnabled = false; btnSave.IsEnabled = true; btnCancel.IsEnabled = true; btnPrevious.IsEnabled = false; btnNext.IsEnabled = false; BindingOperations.ClearBinding(firstNameTextBox, TextBox.TextProperty); BindingOperations.ClearBinding(lastNameTextBox, TextBox.TextProperty); firstNameTextBox.Text = tempFirstName; lastNameTextBox.Text = tempLastName; //apelam metoda // SetValidationBinding(); }
private void btnEdit_Click(object sender, RoutedEventArgs e) { action = ActionState.Edit; string tempPhonenum = firstNameTextBox.Text.ToString(); string tempSubscriber = lastNameTextBox.Text.ToString(); btnNew.IsEnabled = false; btnEdit.IsEnabled = false; btnDelete.IsEnabled = false; btnSave.IsEnabled = true; btnCancel.IsEnabled = true; customerDataGrid.IsEnabled = false; btnPrevious.IsEnabled = false; btnNext.IsEnabled = false; firstNameTextBox.IsEnabled = true; lastNameTextBox.IsEnabled = true; BindingOperations.ClearBinding(firstNameTextBox, TextBox.TextProperty); BindingOperations.ClearBinding(lastNameTextBox, TextBox.TextProperty); SetValidationBinding(); firstNameTextBox.Text = tempPhonenum; lastNameTextBox.Text = tempSubscriber; Keyboard.Focus(firstNameTextBox); }
private void btnEditPr_Click(object sender, RoutedEventArgs e) { action = ActionState.Edit; string tmpName = nameTextBox.Text.ToString(); double tmpPrice = double.Parse(priceTextBox.Text); btnNewPr.IsEnabled = false; btnEditPr.IsEnabled = false; btnDeletePr.IsEnabled = false; btnSavePr.IsEnabled = true; btnCancelPr.IsEnabled = true; btnPrevPr.IsEnabled = false; btnNextPr.IsEnabled = false; productDataGrid.IsEnabled = false; nameTextBox.IsEnabled = true; priceTextBox.IsEnabled = true; BindingOperations.ClearBinding(nameTextBox, TextBox.TextProperty); BindingOperations.ClearBinding(priceTextBox, TextBox.TextProperty); nameTextBox.Text = tmpName; priceTextBox.Text = tmpPrice.ToString(); Keyboard.Focus(nameTextBox); }
private void btnEditC_Click(object sender, RoutedEventArgs e) { action = ActionState.Edit; string tmpFirstName = firstNameTextBox.Text.ToString(); string tmpLastName = lastNameTextBox.Text.ToString(); btnNewC.IsEnabled = false; btnEditC.IsEnabled = false; btnDeleteC.IsEnabled = false; btnSaveC.IsEnabled = true; btnCancelC.IsEnabled = true; btnPrevC.IsEnabled = false; btnNextC.IsEnabled = false; clientDataGrid.IsEnabled = false; firstNameTextBox.IsEnabled = true; lastNameTextBox.IsEnabled = true; BindingOperations.ClearBinding(firstNameTextBox, TextBox.TextProperty); BindingOperations.ClearBinding(lastNameTextBox, TextBox.TextProperty); firstNameTextBox.Text = tmpFirstName; lastNameTextBox.Text = tmpLastName; Keyboard.Focus(firstNameTextBox); }
private void btnDeletePh_Click(object sender, RoutedEventArgs e) { action = ActionState.Delete; string tmpPhName = phNameTextBox.Text.ToString(); string tmpAddress = addressTextBox.Text.ToString(); btnNewPh.IsEnabled = false; btnEditPh.IsEnabled = false; btnDeletePh.IsEnabled = false; btnSavePh.IsEnabled = true; btnCancelPh.IsEnabled = true; btnPrevPh.IsEnabled = false; btnNextPh.IsEnabled = false; pharmacyDataGrid.IsEnabled = false; phNameTextBox.IsEnabled = true; addressTextBox.IsEnabled = true; BindingOperations.ClearBinding(phNameTextBox, TextBox.TextProperty); BindingOperations.ClearBinding(addressTextBox, TextBox.TextProperty); phNameTextBox.Text = tmpPhName; addressTextBox.Text = tmpAddress; }
private void btnEdit2_Click(object sender, RoutedEventArgs e) { action = ActionState.Edit; string tempCustomer = cmbCustomers.SelectedItem.ToString(); string tempInventory = cmbInventory.SelectedItem.ToString(); BindingOperations.ClearBinding(cmbCustomers, ComboBox.SelectedItemProperty); BindingOperations.ClearBinding(cmbInventory, ComboBox.SelectedItemProperty); btnNew2.IsEnabled = false; btnEdit2.IsEnabled = false; btnDelete2.IsEnabled = false; btnCancel2.IsEnabled = true; btnPrev2.IsEnabled = false; btnNext2.IsEnabled = false; cmbCustomers.IsEnabled = true; cmbInventory.IsEnabled = true; cmbCustomers.SelectedItem = tempCustomer; cmbInventory.SelectedItem = tempInventory; }
private void Self_Unloaded([NotNull] object sender, [NotNull] RoutedEventArgs e) { // Detach from host. // Must check for null, unloaded event might be raised even if no loaded event has been raised before! FilterHost?.RemoveColumn(this); var dataGrid = DataGrid; if (dataGrid != null) { dataGrid.SourceUpdated -= DataGrid_SourceOrTargetUpdated; dataGrid.TargetUpdated -= DataGrid_SourceOrTargetUpdated; dataGrid.RowEditEnding -= DataGrid_RowEditEnding; ((INotifyCollectionChanged)dataGrid.Items).CollectionChanged -= DataGrid_CollectionChanged; } // Clear all bindings generated during load. // ReSharper disable once AssignNullToNotNullAttribute BindingOperations.ClearBinding(this, VisibilityProperty); // ReSharper disable once AssignNullToNotNullAttribute BindingOperations.ClearBinding(this, TemplateProperty); BindingOperations.ClearBinding(this, FilterProperty); }
private void btnNew1_Click(object sender, RoutedEventArgs e) { action = ActionState.New; btnNew1.IsEnabled = false; btnEdit1.IsEnabled = false; btnDelete1.IsEnabled = false; btnSave1.IsEnabled = true; btnCancel1.IsEnabled = true; btnPrev1.IsEnabled = false; btnNext1.IsEnabled = false; colorTextBox.IsEnabled = true; makeTextBox.IsEnabled = true; BindingOperations.ClearBinding(colorTextBox, TextBox.TextProperty); BindingOperations.ClearBinding(makeTextBox, TextBox.TextProperty); colorTextBox.Text = ""; makeTextBox.Text = ""; Keyboard.Focus(colorTextBox); }
private void btnDelete_Click(object sender, RoutedEventArgs e) { action = ActionState.Delete; string tempPhonenum = txtPhoneNumber.Text.ToString(); string tempSubscriber = txtSubscriber.Text.ToString(); string tempContract_Value = txtContractValue.Text.ToString(); string tempContract_Date = txtContractDate.Text.ToString(); btnNew.IsEnabled = false; btnEdit.IsEnabled = false; btnDelete.IsEnabled = false; btnSave.IsEnabled = true; btnCancel.IsEnabled = true; lstPhones.IsEnabled = false; btnPrevious.IsEnabled = false; btnNext.IsEnabled = false; BindingOperations.ClearBinding(txtPhoneNumber, TextBox.TextProperty); BindingOperations.ClearBinding(txtSubscriber, TextBox.TextProperty); txtPhoneNumber.Text = tempPhonenum; txtSubscriber.Text = tempSubscriber; txtContractValue.Text = tempContract_Value; txtContractDate.Text = tempContract_Date; }
private static void OnIsActivePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { if (_defaultProperties.ContainsKey(d.GetType())) { var defaultProperty = _defaultProperties[d.GetType()]; if ((bool)e.NewValue) { var binding = BindingOperations.GetBinding(d, defaultProperty); if (binding != null) { string bindingPath = binding.Path.Path; BindingOperations.SetBinding(d, IsChangedProperty, new Binding(bindingPath + "IsChanged")); CreateOriginalValueBinding(d, bindingPath + "OriginalValue"); } } else { BindingOperations.ClearBinding(d, IsChangedProperty); BindingOperations.ClearBinding(d, OriginalValueProperty); } } }
private void ordDelete_Click(object sender, RoutedEventArgs e) { action = ActionState.Delete; string tempCustomer = cmbCustomers.Text.ToString(); string tempProducts = cmbProducts.Text.ToString(); ordNew.IsEnabled = false; ordEdit.IsEnabled = false; ordDelete.IsEnabled = false; ordSave.IsEnabled = true; ordCancel.IsEnabled = true; ordersDataGrid.IsEnabled = false; ordPrev.IsEnabled = false; ordNext.IsEnabled = false; BindingOperations.ClearBinding(cmbCustomers, ComboBox.TextProperty); BindingOperations.ClearBinding(cmbProducts, ComboBox.TextProperty); cmbCustomers.Text = tempCustomer; cmbProducts.Text = tempProducts; }
/// <summary> /// 卡片离开怪物区时,怪物区控件的操作 /// </summary> /// <param name="cv">怪物区控件</param> /// <param name="card">卡片</param> public static void removeFromMonsterOP(MyCanvas cv, CardUI card) { int count = cv.Children.Count; if (count == 0) { Binding bind = new Binding(); BindingOperations.ClearBinding(cv.tb_atkDef, TextBlock.TextProperty); cv.tb_atkDef.IsHitTestVisible = false; return; } CardUI top = cv.Children[count - 1] as CardUI; if (top.Status == Status.BACK_ATK || top.Status == Status.FRONT_ATK) { Service.CardOperate.sort_XYZ_atk(cv); } else { Service.CardOperate.sort_XYZ_def(cv); } bindingAtk(cv, top);//绑定顶层卡片攻击力 }
private static void OnColumnHeadersSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { var dataGrid = (DataGrid)d; var headers = (IEnumerable)e.NewValue; (dataGrid.GetValue(ColumnHeaderListenerProperty) as IDisposable)?.Dispose(); dataGrid.ClearValue(ColumnHeaderListenerProperty); if (headers == null) { foreach (var column in dataGrid.Columns) { BindingOperations.ClearBinding(column, DataGridColumn.HeaderProperty); } dataGrid.RemoveHandler(Events.ColumnsChanged, OnColumnsChangedHandler); return; } dataGrid.SetCurrentValue(ColumnHeaderListenerProperty, new ColumnHeaderListener(dataGrid)); dataGrid.UpdateHandler(Events.ColumnsChanged, OnColumnsChangedHandler); OnColumnsChanged(dataGrid, null); }
private void btnDelete_Click(object sender, RoutedEventArgs e) { action = ActionState.Delete; string tempFirstName = firstNameTextBox.Text.ToString(); string tempLastName = lastNameTextBox.Text.ToString(); btnNew.IsEnabled = false; btnEdit.IsEnabled = false; btnDelete.IsEnabled = false; btnSave.IsEnabled = true; btnCancel.IsEnabled = true; customerDataGrid.IsEnabled = false; btnPrev.IsEnabled = false; btnNext.IsEnabled = false; firstNameTextBox.IsEnabled = false; lastNameTextBox.IsEnabled = false; BindingOperations.ClearBinding(firstNameTextBox, TextBox.TextProperty); BindingOperations.ClearBinding(lastNameTextBox, TextBox.TextProperty); firstNameTextBox.Text = tempFirstName; lastNameTextBox.Text = tempLastName; }
private static void OnRowHeadersChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { var dataGrid = (DataGrid)d; var headers = (IEnumerable)e.NewValue; (dataGrid.GetValue(RowHeaderListenerProperty) as IDisposable)?.Dispose(); dataGrid.ClearValue(RowHeaderListenerProperty); if (headers == null) { foreach (DataGridRow row in dataGrid.Items) { BindingOperations.ClearBinding(row, DataGridRow.HeaderProperty); } dataGrid.RemoveHandler(Events.RowsChanged, OnRowsChangedHandler); return; } dataGrid.SetValue(RowHeaderListenerProperty, new RowHeaderListener(dataGrid)); dataGrid.UpdateHandler(Events.RowsChanged, OnRowsChangedHandler); OnRowsChanged(dataGrid, null); }
public static void ResetBindingOf( this DependencyObject dependencyObject, DependencyProperty dependencyProperty, BindingBase binding = null ) { if (dependencyObject == null) { return; } if (dependencyProperty == null) { return; } BindingOperations.ClearBinding(dependencyObject, dependencyProperty); if (binding != null) { BindingOperations.SetBinding(dependencyObject, dependencyProperty, binding); } }
static void OnIsEnabledChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { if (!(d is DXExpander)) { return; } if ((bool)e.NewValue) { BindingOperations.SetBinding(d, IsExpanderExpandedProperty, new Binding("IsExpanded") { Source = d, Mode = BindingMode.TwoWay }); BindingOperations.SetBinding(d, IsExpanderCollapsingProperty, new Binding("Collapsing") { Source = d }); } else { BindingOperations.ClearBinding(d, IsExpanderExpandedProperty); BindingOperations.ClearBinding(d, IsExpanderCollapsingProperty); } }
private void btnNew_Click(object sender, RoutedEventArgs e) { action = ActionState.New; btnNew.IsEnabled = false; btnEdit.IsEnabled = false; btnDelete.IsEnabled = false; btnSave.IsEnabled = true; btnCancel.IsEnabled = true; lstPhones.IsEnabled = false; btnPrevious.IsEnabled = false; btnNext.IsEnabled = false; txtPhoneNumber.IsEnabled = true; txtSubscriber.IsEnabled = true; BindingOperations.ClearBinding(txtPhoneNumber, TextBox.TextProperty); BindingOperations.ClearBinding(txtSubscriber, TextBox.TextProperty); BindingOperations.ClearBinding(txtContract_value, TextBox.TextProperty); BindingOperations.ClearBinding(txtContract_date, TextBox.TextProperty); txtPhoneNumber.Text = ""; txtSubscriber.Text = ""; txtContract_value.Text = ""; txtContract_date.Text = ""; Keyboard.Focus(txtPhoneNumber); }
/// <summary> /// Initializes a new instance of the <see cref="WatermarkAdorner"/> class /// </summary> /// <param name="adornedElement"><see cref="UIElement"/> to be adorned</param> /// <param name="watermark">The watermark</param> public WatermarkAdorner(UIElement adornedElement, object watermark) : base(adornedElement) { this.IsHitTestVisible = false; this.contentPresenter = new ContentPresenter(); this.contentPresenter.Content = watermark; this.contentPresenter.Opacity = 0.5; this.contentPresenter.Margin = new Thickness(Control.Margin.Left + Control.Padding.Left, Control.Margin.Top + Control.Padding.Top, 0, 0); if (this.Control is ItemsControl && !(this.Control is ComboBox)) { this.contentPresenter.VerticalAlignment = VerticalAlignment.Center; this.contentPresenter.HorizontalAlignment = HorizontalAlignment.Center; } // Hide the control adorner when the adorned element is hidden Binding binding = new Binding("IsVisible"); binding.Source = adornedElement; binding.Converter = new BooleanToVisibilityConverter(); BindingOperations.ClearBinding(this, VisibilityProperty); }
private void btnDelete_Ord_Click(object sender, RoutedEventArgs e) { action = ActionState.Delete; string tempCustId = txtCustId.Text.ToString(); string tempCarId = txtCarId.Text.ToString(); btnNew_Ord.IsEnabled = false; btnEdit_Ord.IsEnabled = false; btnDelete_Ord.IsEnabled = false; btnSave_Ord.IsEnabled = true; btnCancel_Ord.IsEnabled = true; btnNext_Ord.IsEnabled = false; btnPrev_Ord.IsEnabled = false; ordersDataGrid.IsEnabled = false; txtCarId.IsEnabled = true; txtCustId.IsEnabled = true; txtOrderId.IsEnabled = false; BindingOperations.ClearBinding(txtCarId, TextBox.TextProperty); BindingOperations.ClearBinding(txtCustId, TextBox.TextProperty); txtCarId.Text = tempCarId; txtCustId.Text = tempCustId; }
private void btnEdit_Click(object sender, RoutedEventArgs e) { action = ActionState.Edit; string tempPhonenum = txtPhoneNumber.Text.ToString(); string tempSubscriber = txtSubscriber.Text.ToString(); btnCancel.IsEnabled = true; btnSave.IsEnabled = true; btnNew.IsEnabled = false; btnEdit.IsEnabled = false; lstPhones.IsEnabled = false; btnPrevious.IsEnabled = false; btnNext.IsEnabled = false; txtPhoneNumber.IsEnabled = true; txtSubscriber.IsEnabled = true; BindingOperations.ClearBinding(txtPhoneNumber, TextBox.TextProperty); BindingOperations.ClearBinding(txtSubscriber, TextBox.TextProperty); txtPhoneNumber.Text = tempPhonenum; txtSubscriber.Text = tempSubscriber; Keyboard.Focus(txtPhoneNumber); }
private void btnEditInv_Click(object sender, RoutedEventArgs e) { action = ActionState.Edit; string tempColor = colorTextBox.Text.ToString(); string tempMake = makeTextBox.Text.ToString(); btnNewInv.IsEnabled = false; btnEditInv.IsEnabled = false; btnDeleteInv.IsEnabled = false; btnSaveInv.IsEnabled = true; btnCancelInv.IsEnabled = true; inventoryDataGrid.IsEnabled = false; btnPreviousInv.IsEnabled = false; btnNextInv.IsEnabled = false; colorTextBox.IsEnabled = true; makeTextBox.IsEnabled = true; BindingOperations.ClearBinding(colorTextBox, TextBox.TextProperty); BindingOperations.ClearBinding(makeTextBox, TextBox.TextProperty); colorTextBox.Text = tempColor; makeTextBox.Text = tempMake; Keyboard.Focus(colorTextBox); }
private void ChangeBinding(string bindingTarget, bool twoWay = false) { if (ShowExpressionOnly) { bindingTarget = "ExpressionStr"; twoWay = true; } else { realBinding = (target : bindingTarget, mode : twoWay); } ContentBox.GetBindingExpression(TextBox.TextProperty)?.UpdateSource(); BindingOperations.ClearBinding(ContentBox, TextBox.TextProperty); var nwBinding = new Binding(bindingTarget) { UpdateSourceTrigger = UpdateSourceTrigger.Explicit, Mode = (twoWay) ? BindingMode.TwoWay : BindingMode.OneWay }; ContentBox.SetBinding(TextBox.TextProperty, nwBinding); }