示例#1
0
        public void DataBinding_BindToBooleanMember()
        {
            ThreadRunner.RunInSTA(delegate {
                //Create the visual
                BoolToVisibilityConverterTestVisual testVisual = new BoolToVisibilityConverterTestVisual();

                //Create the object that the visual will databind to.
                BoolToVisibilityConverterBindableBoolClass dataContext = new BoolToVisibilityConverterBindableBoolClass();
                dataContext.IsVisible1 = true;
                dataContext.IsVisible2 = true;
                testVisual.DataContext = dataContext;

                //Render the visual
                RenderUtility.RenderVisual(testVisual);

                //Check the visibility of the controls
                Assert.IsTrue(testVisual.nonInvertingVisibilityControl.Visibility == Visibility.Visible);
                Assert.IsTrue(testVisual.invertingVisibilityControl.Visibility == Visibility.Collapsed);

                //Negate the visibilities to check that ConvertBack works ok.
                testVisual.NegateCurrentVisbilities();
                RenderUtility.RenderVisual(testVisual);

                //Check the visibility flags in our datacontext
                Assert.IsTrue(dataContext.IsVisible1 == false);
                Assert.IsTrue(dataContext.IsVisible2 == false);
            });
        }
        /// <summary>
        /// A common helper method that tests running a test in an apartment from an apartment.
        /// </summary>
        private bool RunInApartmentFromApartment(ApartmentState fromApartMent, ApartmentState inApartment)
        {
            bool wasRunInCorrectApartment = false;

            Thread runnerThread = new Thread((ThreadStart) delegate
            {
                if (inApartment == ApartmentState.MTA)
                {
                    ThreadRunner.RunInMTA(delegate
                    {
                        wasRunInCorrectApartment = Thread.CurrentThread.GetApartmentState() == inApartment;
                    });
                }
                else if (inApartment == ApartmentState.STA)
                {
                    ThreadRunner.RunInSTA(delegate
                    {
                        wasRunInCorrectApartment = Thread.CurrentThread.GetApartmentState() == inApartment;
                    });
                }
            }
                                             );

            runnerThread.SetApartmentState(fromApartMent);
            runnerThread.Start();
            runnerThread.Join();

            return(wasRunInCorrectApartment);
        }
        public void FindChildControl_IndexTooGreat()
        {
            ThreadRunner.RunInSTA(delegate
            {
                DependencyObjectExtensionsTestVisual visual = new DependencyObjectExtensionsTestVisual();
                RenderUtility.RenderVisual(visual);

                TextBox tb = visual.FindChildControl <TextBox>(4);
                Assert.IsNull(tb);
            });
        }
        public void FindChildControl_IndexLessThanZero()
        {
            ThreadRunner.RunInSTA(delegate
            {
                DependencyObjectExtensionsTestVisual visual = new DependencyObjectExtensionsTestVisual();
                RenderUtility.RenderVisual(visual);

                TextBox tb = visual.FindChildControl <TextBox>(-1);
                Assert.IsTrue(tb != null && tb.Text == "TextBox 1");
            });
        }
        public void FindParentControl_ControlNull()
        {
            ThreadRunner.RunInSTA(delegate
            {
                DependencyObjectExtensionsTestVisual visual = null;
                RenderUtility.RenderVisual(visual);

                StackPanel sp = visual.FindParentControl <StackPanel>();

                Assert.IsNull(sp);
            });
        }
        public void FindParentControl_ParentDoesNotExists()
        {
            ThreadRunner.RunInSTA(delegate
            {
                DependencyObjectExtensionsTestVisual visual = new DependencyObjectExtensionsTestVisual();
                RenderUtility.RenderVisual(visual);

                StackPanel intermediateStackPanel = visual.IntermediatePanel;

                TabControl g = intermediateStackPanel.FindParentControl <TabControl>();

                Assert.IsNull(g);
            });
        }
        public void FindParentControl_ParentExists()
        {
            ThreadRunner.RunInSTA(delegate
            {
                DependencyObjectExtensionsTestVisual visual = new DependencyObjectExtensionsTestVisual();
                RenderUtility.RenderVisual(visual);

                StackPanel intermediateStackPanel = visual.IntermediatePanel;

                StackPanel sp = intermediateStackPanel.FindParentControl <StackPanel>();

                Assert.IsTrue(sp != null && sp.Name == "RootPanel");
            });
        }
        public void FindChildControl_FindFirst()
        {
            ThreadRunner.RunInSTA(delegate
            {
                DependencyObjectExtensionsTestVisual visual = new DependencyObjectExtensionsTestVisual();
                RenderUtility.RenderVisual(visual);

                //Assume first element
                TextBox tb = visual.FindChildControl <TextBox>();
                Assert.IsTrue(tb != null && tb.Text == "TextBox 1");

                //Explicitly findfirst element
                tb = visual.FindChildControl <TextBox>(0);
                Assert.IsTrue(tb != null && tb.Text == "TextBox 1");
            });
        }
示例#9
0
        public void DataBinding_BindToNonBooleanMember()
        {
            ThreadRunner.RunInSTA(delegate
            {
                //Create the visual
                BoolToVisibilityConverterTestVisual testVisual = new BoolToVisibilityConverterTestVisual();

                //Create the object that the visual will databind to.
                BoolToVisibilityConverterBindableNonBoolClass dataContext = new BoolToVisibilityConverterBindableNonBoolClass();
                dataContext.IsVisible1 = "some string 1";
                dataContext.IsVisible2 = "some string 2";
                testVisual.DataContext = dataContext;

                //Render the visual
                RenderUtility.RenderVisual(testVisual);
            });
        }
        public void FindChildControl_FindNonExistentControl()
        {
            ThreadRunner.RunInSTA(delegate
            {
                DependencyObjectExtensionsTestVisual visual = new DependencyObjectExtensionsTestVisual();
                RenderUtility.RenderVisual(visual);

                //Attempt to find first, implicit
                TabControl tc = visual.FindChildControl <TabControl>();
                Assert.IsNull(tc);

                //Attempt to find first, explicit
                tc = visual.FindChildControl <TabControl>(0);
                Assert.IsNull(tc);

                //Attempt to find other than first
                tc = visual.FindChildControl <TabControl>(2);
                Assert.IsNull(tc);
            });
        }