Пример #1
0
        public virtual void CommandInDataTemplate()
        {
            string xaml  = @"
<Grid>
    <Grid.Resources>
        <DataTemplate x:Key=""temp"">
            <Button Command=""{b:DXCommand 'Method($test:BindingTests_a.StaticIntProp)'}""/>
        </DataTemplate>
    </Grid.Resources>
    <ContentControl Content=""{b:DXBinding}"" ContentTemplate=""{StaticResource temp}""/>
    <ContentControl Content=""{b:DXBinding}"" ContentTemplate=""{StaticResource temp}""/>
</Grid>
";
            var    panel = BindingTestHelper.LoadXaml <Grid>(xaml);

            BindingTestHelper.VisualTest(panel, () => {
                BindingTests_a.Static(2);
                var vm            = CommandTests_a.Create();
                var tb1           = LayoutTreeHelper.GetVisualChildren(panel.Children[0]).OfType <Button>().First();
                var tb2           = LayoutTreeHelper.GetVisualChildren(panel.Children[1]).OfType <Button>().First();
                panel.DataContext = vm;
                BindingTestHelper.DoEvents(panel);
                BindingTestHelper.DoCommand(tb1);
                Assert.AreEqual(1, vm.MethodCounter);
                BindingTestHelper.DoCommand(tb2);
                Assert.AreEqual(2, vm.MethodCounter);
            });
        }
Пример #2
0
        public virtual void EventInDataTemplate()
        {
            string xaml  = @"
<Grid>
    <Grid.Resources>
        <DataTemplate x:Key=""temp"">
            <test:EventTests_visual CustomEvent=""{b:DXEvent 'Do4($test:BindingTests_a.StaticIntProp)'}""/>
        </DataTemplate>
    </Grid.Resources>
    <ContentControl Content=""{b:DXBinding}"" ContentTemplate=""{StaticResource temp}""/>
    <ContentControl Content=""{b:DXBinding}"" ContentTemplate=""{StaticResource temp}""/>
</Grid>
";
            var    panel = BindingTestHelper.LoadXaml <Grid>(xaml);

            BindingTestHelper.VisualTest(panel, () => {
                BindingTests_a.Static(2);
                var vm            = EventTests_a.Create();
                var tb1           = LayoutTreeHelper.GetVisualChildren(panel.Children[0]).OfType <EventTests_visual>().First();
                var tb2           = LayoutTreeHelper.GetVisualChildren(panel.Children[1]).OfType <EventTests_visual>().First();
                panel.DataContext = vm;
                BindingTestHelper.DoEvents(panel);
                tb1.RaiseCustomEvent();
                tb2.RaiseCustomEvent();
                Assert.AreEqual(2, vm.Do4Counter);
            });
        }
Пример #3
0
        public virtual void Parameters()
        {
            string xaml = @"
<Grid x:Name=""root"">
    <Grid.Resources>
        <Style x:Key=""st"" TargetType=""TextBox"">
            <Setter Property=""Text"" Value=""{b:DXBinding IntProp+$test:BindingTests_a.StaticIntProp,
                                        BackExpr='IntProp=int.Parse(@v)-$test:BindingTests_a.StaticIntProp'}""/>
        </Style>
    </Grid.Resources>
    <test:EventTests_visual x:Name=""bt1"" CustomEvent=""{b:DXEvent 'Do3(@args, @e(bt2), @sender)'}""/>
    <test:EventTests_visual x:Name=""bt2"" CustomEvent=""{b:DXEvent 'Do3(@args, @e(bt1), @sender)'}""/>
</Grid>";

            var  vm    = EventTests_a.Create();
            Grid panel = BindingTestHelper.LoadXaml <Grid>(xaml);
            var  bt1   = (EventTests_visual)panel.Children[0];
            var  bt2   = (EventTests_visual)panel.Children[1];

            panel.DataContext = vm;
            BindingTestHelper.DoEvents(panel);
            bt1.RaiseCustomEvent();
            Assert.AreEqual(bt2, vm.Do3Parameter);
            Assert.AreEqual(EventArgs.Empty, vm.Do3EventArgs);
            Assert.AreEqual(bt1, vm.Do3Sender);
            bt2.RaiseCustomEvent();
            Assert.AreEqual(bt1, vm.Do3Parameter);
            Assert.AreEqual(EventArgs.Empty, vm.Do3EventArgs);
            Assert.AreEqual(bt2, vm.Do3Sender);
        }
Пример #4
0
        public void AssignOperator_ElementName()
        {
            string xaml  = @"
<Grid x:Name=""panel"" Tag=""{b:DXBinding '1'}"">
    <Button Command=""{b:DXCommand Execute='@e(panel).Tag = @e(panel).Tag + 1'}""/>
</Grid>
";
            var    panel = BindingTestHelper.LoadXaml <Grid>(xaml);
            var    bt    = (Button)panel.Children[0];

            Assert.AreEqual(1, panel.Tag);
            BindingTestHelper.DoCommand(bt); BindingTestHelper.DoEvents(bt);
            Assert.AreEqual(2, panel.Tag);
        }
Пример #5
0
        public void AssignOperator_ElementName()
        {
            string xaml   = @"
<Grid x:Name=""panel"" Tag=""{b:DXBinding '1'}"">
    <test:EventTests_visual CustomRoutedEvent=""{b:DXEvent Handler='@e(panel).Tag = @e(panel).Tag + 1'}""/>
</Grid>
";
            var    panel  = BindingTestHelper.LoadXaml <Grid>(xaml);
            var    visual = (EventTests_visual)panel.Children[0];

            Assert.AreEqual(1, panel.Tag);
            visual.RaiseCustomRoutedEvent();
            Assert.AreEqual(2, panel.Tag);
        }
Пример #6
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);
        }