public void Feature_Bindings_shall_requery_if_bound_contextid_is_changed_at_the_ancestor()
        {
            Dictionary <string, Feature> Rules = new Dictionary <string, Feature>
            {
                { "One/BoundTwo/Three", new Feature(false, false) },
                { "One/AlteredTwo/Three", new Feature(true, true) },
                { "One/BoundTwo/TemplatedThree", new Feature(false, false) },
                { "One/AlteredTwo/TemplatedThree", new Feature(true, true) }
            };
            ContextValues ContextValues = new ContextValues("BoundTwo");

            TestFeatureSource TestSource     = new TestFeatureSource(Rules);
            IUiFeatureManager FeatureManager = new UiFeatureManager(new[] { TestSource });

            UiFeatureManagementControlTree ControlTree = new UiFeatureManagementControlTree();

            ControlTree.DataContext = ContextValues;
            ControlTree.Two.SetBinding(UiFeatureManagement.ContextProperty, "Context");
            UiFeatureManagement.SetManager(ControlTree, FeatureManager);

            Assert.AreEqual(Visibility.Collapsed, ControlTree.Three.Visibility);
            Assert.AreEqual(Visibility.Collapsed, ControlTree.TemplatedThree.Visibility);
            Assert.IsFalse(ControlTree.Three.IsEnabled);
            Assert.IsFalse(ControlTree.TemplatedThree.IsEnabled);

            ContextValues.Context = "AlteredTwo";

            Assert.AreEqual(Visibility.Visible, ControlTree.Three.Visibility);
            Assert.AreEqual(Visibility.Visible, ControlTree.TemplatedThree.Visibility);
            Assert.IsTrue(ControlTree.Three.IsEnabled);
            Assert.IsTrue(ControlTree.TemplatedThree.IsEnabled);
        }
        public void Feature_Bindings_shall_requery_if_contextid_is_changed_at_the_element()
        {
            Dictionary <string, Feature> Rules = new Dictionary <string, Feature>
            {
                { "One/Two/Three", new Feature(false, false) },
                { "One/Two/AlteredThree", new Feature(true, true) },
                { "One/Two/TemplatedThree", new Feature(false, false) },
                { "One/Two/AlteredTemplatedThree", new Feature(true, true) }
            };

            TestFeatureSource TestSource     = new TestFeatureSource(Rules);
            IUiFeatureManager FeatureManager = new UiFeatureManager(new[] { TestSource });

            UiFeatureManagementControlTree ControlTree = new UiFeatureManagementControlTree();

            UiFeatureManagement.SetManager(ControlTree, FeatureManager);

            Assert.AreEqual(Visibility.Collapsed, ControlTree.Three.Visibility);
            Assert.AreEqual(Visibility.Collapsed, ControlTree.TemplatedThree.Visibility);
            Assert.IsFalse(ControlTree.Three.IsEnabled);

            UiFeatureManagement.SetContext(ControlTree.Three, "AlteredThree");
            UiFeatureManagement.SetContext(ControlTree.TemplatedThree, "AlteredTemplatedThree");

            Assert.AreEqual(Visibility.Visible, ControlTree.Three.Visibility);
            Assert.AreEqual(Visibility.Visible, ControlTree.TemplatedThree.Visibility);
            Assert.IsTrue(ControlTree.Three.IsEnabled);
        }
        public void Feature_Bindings_shall_reflect_values_of_manager()
        {
            TestFeatureSource TestSource     = new TestFeatureSource(true, true);
            IUiFeatureManager FeatureManager = new UiFeatureManager(new[] { TestSource });

            UiFeatureManagementControlTree ControlTree = new UiFeatureManagementControlTree();

            UiFeatureManagement.SetManager(ControlTree, FeatureManager);

            Assert.AreEqual(Visibility.Visible, ControlTree.Three.Visibility);
            Assert.IsTrue(ControlTree.Three.IsEnabled);
            Assert.IsFalse(ControlTree.ReadonlyThree.IsReadOnly);

            TestSource.Enabled = false;

            Assert.AreEqual(Visibility.Visible, ControlTree.Three.Visibility);
            Assert.IsFalse(ControlTree.Three.IsEnabled);
            Assert.IsFalse(ControlTree.TemplatedThree.IsEnabled);
            Assert.IsTrue(ControlTree.ReadonlyThree.IsReadOnly);

            TestSource.Visible = false;

            Assert.AreEqual(Visibility.Collapsed, ControlTree.Three.Visibility);
            Assert.IsFalse(ControlTree.Three.IsEnabled);
            Assert.IsFalse(ControlTree.TemplatedThree.IsEnabled);
            Assert.IsTrue(ControlTree.ReadonlyThree.IsReadOnly);
        }
Example #4
0
        private static void ContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            DependencyObject Element = (DependencyObject)sender;

            // Clear local path, so that parent value is inherited for this element
            UiFeatureManagement.ReEvaluateContextPath(Element);
        }
Example #5
0
            /// <summary/>
            protected ValueWrapperBase(DependencyObject target)
            {
                UiFeatureManagement.AddContextPathChangedEventHandler(target, this.ContextChanged);
                UiFeatureManagement.AddManagerChangedEventHandler(target, this.ManagerChanged);

                this.Context = UiFeatureManagement.GetContextPath(target);

                this.UpdateManager(UiFeatureManagement.GetManager(target));
            }
Example #6
0
        private static void ReEvaluateContextPath(DependencyObject element)
        {
            UiFeatureManagement.ClearContextPath(element);

            //Get (inherited) parent path
            string ParentContextPath = UiFeatureManagement.GetContextPath(element);
            string Context           = UiFeatureManagement.GetContext(element);

            if (Context != null)
            {
                //Compute and set new path
                UiFeatureManagement.SetContextPath(element, ParentContextPath != null ? $"{ParentContextPath}/{Context}" : Context);
            }
            UiFeatureManagement.NotifyChildrenThatContextPathChanged(element);
        }
        public void Feature_Bindings_shall_requery_if_manager_sends_featurechanged_event()
        {
            Dictionary <string, Feature> Rules = new Dictionary <string, Feature>
            {
                { "One/Two/Three", new Feature(false, false) },
                { "One/Two/TemplatedThree", new Feature(false, false) },
                { "One/Two/Hyperlink", new Feature(false, false) },
            };

            Dictionary <string, Feature> NewRules = new Dictionary <string, Feature>
            {
                { "One/Two/Three", new Feature(true, true) },
                { "One/Two/TemplatedThree", new Feature(true, true) },
                { "One/Two/Hyperlink", new Feature(true, true) },
            };

            TestFeatureSource TestSource        = new TestFeatureSource(Rules);
            TestFeatureSource NewTestSource     = new TestFeatureSource(NewRules);
            IUiFeatureManager FeatureManager    = new UiFeatureManager(new[] { TestSource });
            IUiFeatureManager NewFeatureManager = new UiFeatureManager(new[] { NewTestSource });

            UiFeatureManagementControlTree ControlTree = new UiFeatureManagementControlTree();

            UiFeatureManagement.SetManager(ControlTree, FeatureManager);

            Assert.AreEqual(Visibility.Collapsed, ControlTree.Three.Visibility);
            Assert.AreEqual(Visibility.Collapsed, ControlTree.TemplatedThree.Visibility);
            Assert.IsFalse(ControlTree.Three.IsEnabled);
            Assert.IsFalse(ControlTree.TemplatedThree.IsEnabled);
            Assert.IsFalse(ControlTree.Hyperlink.IsEnabled);

            UiFeatureManagement.SetManager(ControlTree, NewFeatureManager);

            Assert.AreEqual(Visibility.Visible, ControlTree.Three.Visibility);
            Assert.AreEqual(Visibility.Visible, ControlTree.TemplatedThree.Visibility);
            Assert.IsTrue(ControlTree.Three.IsEnabled);
            Assert.IsTrue(ControlTree.TemplatedThree.IsEnabled);
            Assert.IsTrue(ControlTree.Hyperlink.IsEnabled);
        }
        public void Feature_Bindings_shall_query_the_right_contextids()
        {
            Dictionary <string, Feature> Rules = new Dictionary <string, Feature>
            {
                { "One/Two/Three", new Feature(true, false) },
                { "One/Two/TemplatedThree", new Feature(true, false) },
                { "One/Two/OtherThree", new Feature(true, true) },
            };

            TestFeatureSource TestSource     = new TestFeatureSource(Rules);
            IUiFeatureManager FeatureManager = new UiFeatureManager(new[] { TestSource });

            UiFeatureManagementControlTree ControlTree = new UiFeatureManagementControlTree();

            UiFeatureManagement.SetManager(ControlTree, FeatureManager);

            Assert.AreEqual(Visibility.Visible, ControlTree.Three.Visibility);
            Assert.IsFalse(ControlTree.Three.IsEnabled);
            Assert.AreEqual(Visibility.Visible, ControlTree.TemplatedThree.Visibility);
            Assert.IsFalse(ControlTree.TemplatedThree.IsEnabled);
            Assert.AreEqual(Visibility.Visible, ControlTree.OtherThree.Visibility);
            Assert.IsTrue(ControlTree.OtherThree.IsEnabled);
        }
Example #9
0
        private static void NotifyChildrenThatContextPathChanged(DependencyObject element)
        {
            if (element is Visual || element is Visual3D)
            {
                for (int Index = 0; Index < VisualTreeHelper.GetChildrenCount(element); Index++)
                {
                    DependencyObject Child = VisualTreeHelper.GetChild(element, Index);

                    if (Child.ReadLocalValue(UiFeatureManagement.ContextPathProperty) != DependencyProperty.UnsetValue)
                    //if ( UIFeatureManagement.GetContext(Child) != null)
                    {
                        //there is a Context registered. this means, the context path must be re-evaluated.
                        //re-evaluation of children will be done in the called method
                        UiFeatureManagement.ReEvaluateContextPath(Child);
                    }
                    else
                    {
                        //no context is specified here, so check the children
                        UiFeatureManagement.NotifyChildrenThatContextPathChanged(Child);
                    }
                }
            }
        }
        public void Feature_Bindings_shall_query_the_right_bound_contextids()
        {
            Dictionary <string, Feature> Rules = new Dictionary <string, Feature>
            {
                { "One/Two/BoundThree", new Feature(true, false) },
                { "One/Two/BoundTemplatedThree", new Feature(true, false) },
            };

            TestFeatureSource TestSource     = new TestFeatureSource(Rules);
            IUiFeatureManager FeatureManager = new UiFeatureManager(new[] { TestSource });

            UiFeatureManagementControlTree ControlTree = new UiFeatureManagementControlTree();

            ControlTree.DataContext = new ContextValues("BoundThree");
            ControlTree.Three.SetBinding(UiFeatureManagement.ContextProperty, "Context");
            ControlTree.TemplatedThree.DataContext = new ContextValues("BoundTemplatedThree");
            ControlTree.TemplatedThree.SetBinding(UiFeatureManagement.ContextProperty, "Context");
            UiFeatureManagement.SetManager(ControlTree, FeatureManager);

            Assert.AreEqual(Visibility.Visible, ControlTree.Three.Visibility);
            Assert.AreEqual(Visibility.Visible, ControlTree.TemplatedThree.Visibility);
            Assert.IsFalse(ControlTree.Three.IsEnabled);
            Assert.IsFalse(ControlTree.TemplatedThree.IsEnabled);
        }