Ejemplo n.º 1
0
        // Registers any controls that have changed, so that when ApplyBindingsToItems is called, only updated controls are applied
        void FloatingDialog_SourceUpdated(object sender, DataTransferEventArgs e)
        {
            FrameworkElement  control = (FrameworkElement)sender;
            BindingExpression exp     = control.GetBindingExpression(e.Property);

            // Find the binding data and mark it as changed
            BEData binding = _bindings.Find(bdata => bdata.Exp == exp);

            if (binding != null)
            {
                binding.HasValueChanged = true;
            }
        }
Ejemplo n.º 2
0
        private void ApplyBatchCheckboxes(bool createOnly)
        {
            // do not use foreach beacuse it causes inner delegates to work with the wrong object (enumerator.Current)
            for (int i = 0; i < _bindings.Count; i++)
            {
                BEData bedata = _bindings[i];

                // In batch mode, attach a checkbox to this control for marking it as 'please override'
                if (bedata.Obj is Control && ((Control)bedata.Obj).Parent is StackPanel && !GetReadOnlyField(bedata.Obj))
                {
                    Control    control    = (Control)bedata.Obj;
                    StackPanel stackPanel = (StackPanel)control.Parent;
                    CheckBox   checkbox   = VisualTree.GetChild <CheckBox>(stackPanel, "__batch__cb");

                    bool created = false;
                    if (checkbox == null && this.IsBatch)
                    {
                        checkbox           = new CheckBox();
                        checkbox.Name      = "__batch__cb";
                        checkbox.ToolTip   = "Check this to override the value of this field for all selected items";
                        checkbox.IsChecked = false;
                        checkbox.Style     = (Style)App.Current.Resources["FormFieldBatchCheckbox"];
                        Action <object, RoutedEventArgs> del = delegate(object sender, RoutedEventArgs e)
                        {
                            bedata.ShouldBatchApply = control.IsEnabled = checkbox.IsChecked.Value;
                        };

                        checkbox.Checked   += new RoutedEventHandler(del);
                        checkbox.Unchecked += new RoutedEventHandler(del);
                        stackPanel.Children.Add(checkbox);
                        created = true;
                    }

                    if (checkbox != null && (!createOnly || created))
                    {
                        checkbox.IsChecked  = false;
                        checkbox.Visibility = IsBatch ? Visibility.Visible : Visibility.Collapsed;
                        control.IsEnabled   = !IsBatch;
                    }
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Recursively finds any binding expressions marked with the DialogFields attached property.
        /// </summary>
        /// <param name="parent"></param>
        void GetDialogFieldBindings(DependencyObject parent)
        {
            if (parent == null)
            {
                return;
            }

            int childCount = VisualTreeHelper.GetChildrenCount(parent);

            for (int i = 0; i < childCount; i++)
            {
                DependencyObject child = VisualTreeHelper.GetChild(parent, i);

                // Disregard anything that isn't an element
                if (!(child is FrameworkElement))
                {
                    continue;
                }

                if (!_scannedControls.Contains(child))
                {
                    _scannedControls.Add(child);

                    // Get the list of bindings
                    object bindingTargets = child.GetValue(DialogFieldsProperty);
                    if (bindingTargets is string)
                    {
                        // Split the string into names
                        string[] properties = (bindingTargets as string).Split(',');
                        foreach (string property in properties)
                        {
                            DependencyProperty dependencyProp =
                                GetDependencyProperty(child.GetType(), property + "Property");

                            if (dependencyProp == null)
                            {
                                continue;
                            }

                            // If the property is valid, retrieve the attached binding expression and add it
                            BindingExpression exp = (child as FrameworkElement).GetBindingExpression(dependencyProp);
                            (child as FrameworkElement).SourceUpdated += new EventHandler <DataTransferEventArgs>(FloatingDialog_SourceUpdated);
                            var bedata = new BEData(exp, child, dependencyProp);
                            _bindings.Add(bedata);
                        }

                        // if (life.IsABitch)
                        //		this.Commit("suicide");
                    }

                    // Bind to tabcontrol
                    if (child is TabControl)
                    {
                        foreach (TabItem tab in ((TabControl)child).Items)
                        {
                            tab.GotFocus += new RoutedEventHandler(tab_GotFocus);
                        }
                    }
                }

                GetDialogFieldBindings(child);
            }
        }