Пример #1
0
        void OnExpressionEditorLoaded(object sender, RoutedEventArgs e)
        {
            ExpressionTextBox expressionTextBox = sender as ExpressionTextBox;

            Fx.Assert(expressionTextBox != null, "sender should be userControl");
            //bind ExpressionProperty of Expression textbox to ModelItem.Condition
            Binding b = new Binding();
            ArgumentToExpressionConverter argumentToExpressionConverter = new ArgumentToExpressionConverter();

            b.Converter = argumentToExpressionConverter;
            b.Mode      = BindingMode.TwoWay;

            b.Source = this.ModelItem;
            b.Path   = new PropertyPath("Condition");
            if (BindingOperations.GetBinding(expressionTextBox, ExpressionTextBox.ExpressionProperty) != null)
            {
                BindingOperations.ClearBinding(expressionTextBox, ExpressionTextBox.ExpressionProperty);
            }
            expressionTextBox.SetBinding(ExpressionTextBox.ExpressionProperty, b);
            //bind OwnerActivityProperty of Expression textbox to ModelItem
            Binding b1 = new Binding();

            b1.Source = this.ModelItem;
            if (BindingOperations.GetBinding(expressionTextBox, ExpressionTextBox.OwnerActivityProperty) != null)
            {
                BindingOperations.ClearBinding(expressionTextBox, ExpressionTextBox.OwnerActivityProperty);
            }
            expressionTextBox.SetBinding(ExpressionTextBox.OwnerActivityProperty, b1);
        }
Пример #2
0
        private void UpdateBinding()
        {
            if (ExpressionTextBox == null || SelectedCell == null)
            {
                return;
            }

            ExpressionTextBox.GetBindingExpression(TextBox.TextProperty)?.UpdateSource();
            BindingOperations.ClearBinding(ExpressionTextBox, TextBox.TextProperty);

            Binding textBinding = null;

            if (SelectedCell.IsEditable)
            {
                textBinding = new Binding("Text")
                {
                    Source = SelectedCell.ContentBox,
                    Mode   = BindingMode.TwoWay,
                    UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
                };
            }
            else
            {
                textBinding = new Binding("ExpressionStr")
                {
                    Source = SelectedCell.DataContext,
                    Mode   = BindingMode.OneWay,
                    UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
                };
            }

            ExpressionTextBox.SetBinding(TextBox.TextProperty, textBinding);
        }