Esempio n. 1
0
        private static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var button = (ButtonBase)d;

            if (button == null)
            {
                return;
            }

            var str = GetProperty(d);

            if (str == null)
            {
                return;
            }
            var select = WPFOperate.FindVisualParent <ListBoxItem>(button);

            var listbox = WPFOperate.FindVisualParent <ListBox>(select);

            if (listbox == null)
            {
                return;
            }
            button.DataContext = BindingEvaluator.GetValue(listbox.DataContext, str);
            button.Click      += (s2, e2) =>
            {
                var command = (ICommand)BindingEvaluator.GetValue(listbox.DataContext, str);
                if (command.CanExecute(@select.DataContext))
                {
                    command.Execute(@select.DataContext);
                }
            };
        }
Esempio n. 2
0
        private static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var listBoxItem = (MenuItem)d;

            if (listBoxItem == null)
            {
                return;
            }


            var str     = GetJumpBinding(d);
            var listbox = WPFOperate.FindVisualParent <FrameworkElement>(listBoxItem, str.RealSource);

            if (listbox == null)
            {
                return;
            }
            var dataContext = listbox.DataContext;

            listBoxItem.Click += (s2, e2) =>
            {
                var command = (ICommand)BindingEvaluator.GetValue(dataContext, str.Property);
                if (command.CanExecute(listBoxItem.DataContext))
                {
                    command.Execute(listBoxItem.DataContext);
                }
            };
        }
Esempio n. 3
0
        private static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var listBoxItem = (FrameworkElement)d;

            if (listBoxItem == null)
            {
                return;
            }
            var str     = GetProperty(d);
            var listbox = WPFOperate.FindVisualParent <ListBox>(listBoxItem);

            if (listbox == null)
            {
                return;
            }
            var dataContext = listbox.DataContext;

            listBoxItem.MouseDown += (s2, e2) =>
            {
                if (e2.ClickCount != 2)
                {
                    return;
                }
                var command = (ICommand)BindingEvaluator.GetValue(dataContext, str);
                if (command.CanExecute(listBoxItem.DataContext))
                {
                    command.Execute(listBoxItem.DataContext);
                }
            };
        }
Esempio n. 4
0
        private static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var button      = (FrameworkElement)d;
            var prop        = GetProperty(d);
            var select      = WPFOperate.FindVisualParent <ListBoxItem>(button);
            var dataContext = select.DataContext;

            select.MouseLeftButtonUp += (s2, e2) =>
            {
                var info = dataContext.GetType().GetProperty(prop);
                var va   = (bool)info.GetValue(dataContext, new object[] {});
                va = !va;
                info.SetValue(dataContext, va, new object[] {});
            };
        }
Esempio n. 5
0
        static void ButtonDataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            var element = sender as FrameworkElement;

            if (element == null)
            {
                return;
            }

            var jumpSupportData = GetJumpSupportData(element);
            var methodPool      = GetMethodPool(element);

            var target = WPFOperate.GetChild <FrameworkElement>(element, jumpSupportData.TargetName);

            if (target == null)
            {
                return;
            }
            Type type = methodPool.GetType();

            MethodInfo info   = type.GetMethod(jumpSupportData.MethodName);
            object     result = null;

            if (jumpSupportData.ArgCount > 1)
            {
                var context2 = GetDataContextSource2(element);
                result = info.Invoke(methodPool, new[] { element.DataContext, context2 });
            }

            else
            {
                result = info.Invoke(methodPool, new[] { element.DataContext });
            }

            PropertyInfo propertyInfo = target.GetType().GetProperty(jumpSupportData.TargetProperty);

            propertyInfo.SetValue(target, result, new object[] { });
        }
Esempio n. 6
0
        private static void OnIsEnabledChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            bool oldIsEnabled = (bool)e.OldValue;
            bool newIsEnabled = (bool)d.GetValue(IsEnabledProperty);

            var itemsControl = d as ItemsControl;

            if (itemsControl == null)
            {
                return;
            }

            if (newIsEnabled)
            {
                itemsControl.Loaded += (ss, ee) =>
                {
                    ScrollViewer scrollviewer = WPFOperate.GetChild <ScrollViewer>(itemsControl);
                    if (scrollviewer != null)
                    {
                        ((ICollectionView)itemsControl.Items).CollectionChanged += (sss, eee) => scrollviewer.ScrollToEnd();
                    }
                };
            }
        }