コード例 #1
0
        public void ParserShouldParseCustomBehaviorMultiParams()
        {
            const string behaviorName = "TestBehavior";
            const string binding = "Text SourceText, Behavior=TestBehavior(stringvalue, 10, null, true, part1.part2), Validate=true";
            var value = new TwoWayBindingMode();
            var resolver = new BindingResourceResolver();
            resolver.AddBehavior(behaviorName, (dataContext, list) =>
            {
                list.Count.ShouldEqual(5);
                list[0].ShouldEqual("stringvalue");
                list[1].ShouldEqual(10);
                list[2].ShouldBeNull();
                list[3].ShouldEqual(true);
                list[4].ShouldEqual("part1.part2");
                return value;
            }, true);
            IBindingParser bindingParser = CreateBindingParser(bindingProvider: new BindingProvider());
            BindingServiceProvider.ResourceResolver = resolver;

            var context = new BindingBuilder(bindingParser.Parse(binding, EmptyContext, new object(), null).Single());
            context.GetData(BindingBuilderConstants.Behaviors).OfType<TwoWayBindingMode>().Single().ShouldEqual(value);
        }
コード例 #2
0
        public void ParserShouldParseCustomBehaviorByName2()
        {
            const string behaviorName = "TestBehavior";
            const string binding = "Text SourceText, TestBehavior=100";
            var value = new TwoWayBindingMode();
            var resolver = new BindingResourceResolver();
            resolver.AddBehavior(behaviorName, (dataContext, list) =>
            {
                list.Count.ShouldEqual(1);
                list[0].ShouldEqual(100);
                return value;
            }, true);
            IBindingParser bindingParser = CreateBindingParser(bindingProvider: new BindingProvider());
            BindingServiceProvider.ResourceResolver = resolver;

            var context = new BindingBuilder(bindingParser.Parse(binding, EmptyContext, new object(), null).Single());
            context.GetData(BindingBuilderConstants.Behaviors).Single().ShouldEqual(value);
        }