Attach() 공개 메소드

Attaches the behavior to the specified region.
public Attach ( ) : void
리턴 void
        public void ShouldRemoveContextToViewRemovedFromRegion()
        {
            var behavior = new BindRegionContextToDependencyObjectBehavior();
            var region = new MockPresentationRegion();
            var view = new MockDependencyObject();
            region.Add(view);
            behavior.Region = region;
            region.Context = "MyContext";
            behavior.Attach();

            region.Remove(view);

            var context = RegionContext.GetObservableContext(view);
            Assert.IsNull(context.Value);
        }
        public void ShouldSetRegionContextOnAlreadyAddedViews()
        {
            var behavior = new BindRegionContextToDependencyObjectBehavior();
            var region = new MockPresentationRegion();
            var view = new MockDependencyObject();
            region.Add(view);
            behavior.Region = region;
            region.Context = "MyContext";

            behavior.Attach();

            var context = RegionContext.GetObservableContext(view);
            Assert.IsNotNull(context.Value);
            Assert.AreEqual("MyContext", context.Value);
        }
        public void ShouldSetRegionContextOnContextChange()
        {
            var behavior = new BindRegionContextToDependencyObjectBehavior();
            var region = new MockPresentationRegion();
            var view = new MockDependencyObject();
            region.Add(view);
            behavior.Region = region;
            region.Context = "MyContext";
            behavior.Attach();
            Assert.AreEqual("MyContext", RegionContext.GetObservableContext(view).Value);

            region.Context = "MyNewContext";
            region.OnPropertyChange("Context");

            Assert.AreEqual("MyNewContext", RegionContext.GetObservableContext(view).Value);
        }
        public async Task ShouldSetRegionContextOnAddedView()
        {
            await ExecuteOnUIThread(() =>
                {
                    var behavior = new BindRegionContextToDependencyObjectBehavior();
                    var region = new MockPresentationRegion();
                    behavior.Region = region;
                    region.Context = "MyContext";
                    var view = new MockDependencyObject();

                    behavior.Attach();
                    region.Add(view);

                    var context = RegionContext.GetObservableContext(view);
                    Assert.IsNotNull(context.Value);
                    Assert.AreEqual("MyContext", context.Value);
                });
        }
        public async Task WhenAViewIsRemovedFromARegion_ThenRegionContextIsNotClearedInRegion()
        {
            await ExecuteOnUIThread(() =>
                {
                    var behavior = new BindRegionContextToDependencyObjectBehavior();
                    var region = new MockPresentationRegion();

                    behavior.Region = region;
                    behavior.Attach();

                    var myView = new MockFrameworkElement();

                    region.Add(myView);
                    region.Context = "new context";

                    region.Remove(myView);

                    Assert.IsNotNull(region.Context);
                });
        }
        public void ViewInRegionCanBeObject()
        {
            var behavior = new BindRegionContextToDependencyObjectBehavior();
            var region = new MockPresentationRegion();

            behavior.Region = region;
            behavior.Attach();

            region.Add(new object());
            region.Context = "new context";
        }