private void CreateScenarioDataField_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e) { // remove binding BindingOperations.ClearAllBindings(DataTextBox); if (DataContext != null && DataContext is CellData) { var myCellData = DataContext as CellData; //set text binding var textBinding = new Binding() { Source = myCellData, Path = new PropertyPath("Content"), Mode = BindingMode.OneWayToSource, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged }; textBinding.ValidationRules.Add(new NumberValidationRule()); DataTextBox.SetBinding(TextBox.TextProperty, textBinding); //set icon if (DataContext is InputCellData) { DataIcon.Source = Resources["InputCellIcon"] as ImageSource; } else if (DataContext is IntermediateCellData) { DataIcon.Source = Resources["IntermediateCellIcon"] as ImageSource; } else if (DataContext is ResultCellData) { DataIcon.Source = Resources["OutputCellIcon"] as ImageSource; } else { DataIcon.Source = Resources["InputCellIcon"] as ImageSource; } } }
private void ScenarioDataField_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e) { // remove binding BindingOperations.ClearAllBindings(DataTextBox); if (DataContext != null && DataContext is ScenarioData) { var scenarioData = DataContext as ScenarioData; //set text binding var textBinding = new Binding { Source = scenarioData, Path = new PropertyPath("Value"), Mode = BindingMode.TwoWay, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged }; DataTextBox.SetBinding(TextBox.TextProperty, textBinding); //set icon if (DataContext is InputData) { DataIcon.Source = Resources["InputCellIcon"] as ImageSource; } else if (DataContext is InvariantData) { DataIcon.Source = Resources["IntermediateCellIcon"] as ImageSource; } else if (DataContext is ConditionData) { DataIcon.Source = Resources["OutputCellIcon"] as ImageSource; } } }