Beispiel #1
0
        private static void ButtonNamedActionPropertyCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            NamedActionButton nab = (NamedActionButton)d;
            Button            btn = nab.btn;

            if (nab._ActionHandler != null)
            {
                btn.Click -= nab._ActionHandler;
            }
            Base.Interfaces.INamedAction na = (Base.Interfaces.INamedAction)e.NewValue;
            Binding headerBinding           = new Binding("Name");

            headerBinding.Source = na;
            headerBinding.Mode   = BindingMode.OneWay;
            headerBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
            BindingOperations.SetBinding(btn, System.Windows.Controls.Button.ContentProperty, headerBinding);
            if (na is ViewModel.Interfaces.IDisplayToUI)
            {
                Binding enabledBinding = new Binding(nameof(ViewModel.Interfaces.IDisplayToUI.IsEnabled));
                enabledBinding.Source = na;
                enabledBinding.Mode   = BindingMode.OneWay;
                enabledBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
                BindingOperations.SetBinding(btn, System.Windows.Controls.Button.IsEnabledProperty, enabledBinding);
                Binding visibilityBinding = new Binding(nameof(ViewModel.Interfaces.IDisplayToUI.IsVisible));
                visibilityBinding.Source              = na;
                visibilityBinding.Mode                = BindingMode.OneWay;
                visibilityBinding.Converter           = new System.Windows.Controls.BooleanToVisibilityConverter();
                visibilityBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
                BindingOperations.SetBinding(btn, System.Windows.Controls.Button.VisibilityProperty, visibilityBinding);
            }
            nab._ActionHandler = (ob, ev) => na.Action(ob, ev);
            btn.Click         += nab._ActionHandler;
        }
        private static void ButtonNamedActionPropertyCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            //System.Diagnostics.Debugger.Break();
            ImageNamedActionButton nab = (ImageNamedActionButton)d;
            Button btn = nab.btn;

            if (nab._ActionHandler != null)
            {
                btn.Click -= nab._ActionHandler;
            }
            Base.Interfaces.INamedAction na = (Base.Interfaces.INamedAction)e.NewValue;
            if (na == null)
            {
                btn.Visibility = Visibility.Collapsed;
                return;
            }
            else
            {
                if (na is ViewModel.Implementations.NamedAction)
                {
                    ViewModel.Implementations.NamedAction vna = na as ViewModel.Implementations.NamedAction;
                    if (!vna.IsVisible)
                    {
                        btn.Visibility = Visibility.Collapsed;
                    }
                }
                btn.Visibility = Visibility.Visible;
            }
            if (!nab._useImage)
            {
                Binding headerBinding = new Binding(nameof(Base.Interfaces.INamedAction.Name));
                headerBinding.Source = na;
                headerBinding.Mode   = BindingMode.OneWay;
                headerBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
                BindingOperations.SetBinding(btn, Button.ContentProperty, headerBinding);
            }
            if (na is ViewModel.Interfaces.IDisplayToUI)
            {
                Binding enabledBinding = new Binding(nameof(ViewModel.Interfaces.IDisplayToUI.IsEnabled));
                enabledBinding.Source = na;
                enabledBinding.Mode   = BindingMode.OneWay;
                enabledBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
                BindingOperations.SetBinding(btn, System.Windows.Controls.Button.IsEnabledProperty, enabledBinding);
                Binding visibilityBinding = new Binding(nameof(ViewModel.Interfaces.IDisplayToUI.IsVisible));
                visibilityBinding.Source              = na;
                visibilityBinding.Mode                = BindingMode.OneWay;
                visibilityBinding.Converter           = new System.Windows.Controls.BooleanToVisibilityConverter();
                visibilityBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
                BindingOperations.SetBinding(btn, System.Windows.Controls.Button.VisibilityProperty, visibilityBinding);
            }
            nab._ActionHandler = (ob, ev) => na.Action(ob, ev);
            btn.Click         += nab._ActionHandler;
        }