Exemplo n.º 1
0
        public void AttachedPropertyTest()
        {
            var bt = BindingTestHelper.BindAssert <Button>(
                "Button", "Command",
                @"{b:DXCommand 
                    Execute='@s.($test:CommandTests_a.AttachedProp) = true'}",
                null, null, false);

            Assert.AreEqual(null, CommandTests_a.GetAttachedProp(bt));
            BindingTestHelper.DoCommand(bt); BindingTestHelper.DoEvents(bt);
            Assert.AreEqual(true, CommandTests_a.GetAttachedProp(bt));
        }
Exemplo n.º 2
0
        public virtual void Arguments()
        {
            var vm = CommandTests_a.Create();
            var bt = BindingTestHelper.BindAssert <Button>("Button", "Command",
                                                           "{b:DXCommand Execute='Do3(@s.Tag.Parameter, @parameter);', CanExecute='CanDo3(@s.Tag.CanDo)'}", null, vm);

            Assert.AreEqual(false, BindingTestHelper.CanDoCommand(bt));
            bt.Tag = new { CanDo = true }; BindingTestHelper.DoEvents(bt);
            Assert.AreEqual(false, BindingTestHelper.CanDoCommand(bt));
            bt.Tag = new { CanDo = true, Parameter = 1 }; BindingTestHelper.DoEvents(bt);
            Assert.AreEqual(false, BindingTestHelper.CanDoCommand(bt));
            bt.CommandParameter = 1; BindingTestHelper.DoEvents(bt);
            Assert.AreEqual(true, BindingTestHelper.CanDoCommand(bt));
            BindingTestHelper.DoCommand(bt);
            Assert.AreEqual(2, vm.Do3Value);
        }
Exemplo n.º 3
0
        public virtual void CommandInStyleSetter()
        {
            string xaml1 = @"
<Grid>
    <Grid.Resources>
        <Style x:Key=""st"" TargetType=""Button"">
            <Setter Property=""Command"" Value=""{b:DXCommand Method($test:BindingTests_a.StaticIntProp)}""/>
        </Style>
    </Grid.Resources>
    <Button Style=""{StaticResource st}""/>
    <Button Style=""{StaticResource st}""/>
</Grid>
";
            string xaml2 = @"
<Grid>
    <Grid.Resources>
        <Style TargetType=""Button"">
            <Setter Property=""Command"" Value=""{b:DXCommand Method($test:BindingTests_a.StaticIntProp)}""/>
        </Style>
    </Grid.Resources>
    <Button/>
    <Button/>
</Grid>
";

            Action <string> test = xamlStr => {
                BindingTests_a.Static(2);
                var panel = BindingTestHelper.LoadXaml <Grid>(xamlStr);
                var tb1   = (Button)panel.Children[0];
                var tb2   = (Button)panel.Children[1];
                var vm    = CommandTests_a.Create();
                panel.DataContext = vm;
                BindingTestHelper.DoEvents(panel);
                BindingTestHelper.DoCommand(tb1);
                Assert.AreEqual(2, vm.MethodValue);
                BindingTests_a.Static(3);
                BindingTestHelper.DoCommand(tb2);
                Assert.AreEqual(3, vm.MethodValue);
            };

            test(xaml1);
            test(xaml2);
        }