Exemple #1
0
        public void Priority()
        {
            var selector = new DXDataTemplateSelector();

            selector.Items.Add(new DXDataTemplateTrigger()
            {
                Binding  = new Binding("Bool"),
                Value    = "True",
                Template = TextBoxTemplate,
            });
            selector.Items.Add(new DXDataTemplateTrigger()
            {
                Binding  = new Binding("Enum"),
                Value    = "Two",
                Template = ButtonTemplate,
            });
            selector.Items.Add(new DXDataTemplateTrigger()
            {
                Template = CheckBoxTemplate,
            });

            Assert.AreEqual(TextBoxTemplate, selector.SelectTemplate(new TestData()
            {
                Bool = true
            }, null));
            Assert.AreEqual(ButtonTemplate, selector.SelectTemplate(new TestData()
            {
                Bool = true, Enum = TestEnum.Two
            }, null));
            Assert.AreEqual(ButtonTemplate, selector.SelectTemplate(new TestData()
            {
                Enum = TestEnum.Two
            }, null));
            Assert.AreEqual(CheckBoxTemplate, selector.SelectTemplate(new TestData(), null));
        }
Exemple #2
0
        public void ThreadSafety()
        {
            DXDataTemplateSelector selector = CreateSimpleSelector();
            Action checkSelector            = () => {
                Assert.AreEqual(TextBoxTemplate, selector.SelectTemplate(new TestData()
                {
                    Bool = true
                }, null));
                Assert.AreEqual(CheckBoxTemplate, selector.SelectTemplate(new TestData(), null));
            };

            checkSelector();

            var thread = new Thread(x => checkSelector());

            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
            thread.Join();
            Assert.AreEqual(ThreadState.Stopped, thread.ThreadState);
        }
Exemple #3
0
        public void NullValue()
        {
            var selector = new DXDataTemplateSelector();

            selector.Items.Add(new DXDataTemplateTrigger()
            {
                Binding  = new Binding("Bool"),
                Template = TextBoxTemplate,
            });
            selector.Items.Add(new DXDataTemplateTrigger()
            {
                Binding  = new Binding("String"),
                Template = CheckBoxTemplate,
            });

            Assert.AreEqual(CheckBoxTemplate, selector.SelectTemplate(new TestData(), null));
            Assert.AreEqual(null, selector.SelectTemplate(new TestData()
            {
                String = ""
            }, null));
        }
Exemple #4
0
        public void DefaultTemplateFirst()
        {
            var selector = new DXDataTemplateSelector();

            selector.Items.Add(new DXDataTemplateTrigger()
            {
                Template = CheckBoxTemplate,
            });
            selector.Items.Add(new DXDataTemplateTrigger()
            {
                Binding  = new Binding("Bool"),
                Value    = "True",
                Template = TextBoxTemplate,
            });

            Assert.AreEqual(TextBoxTemplate, selector.SelectTemplate(new TestData()
            {
                Bool = true
            }, null));
            Assert.AreEqual(CheckBoxTemplate, selector.SelectTemplate(new TestData(), null));
        }
Exemple #5
0
        public void DontFreezeInDesignTime()
        {
            var selector = new DXDataTemplateSelector();

            DesignerProperties.SetIsInDesignMode(selector.Items, true);
            selector.Items.Add(new DXDataTemplateTrigger()
            {
                Template = TextBoxTemplate
            });
            Assert.AreEqual(TextBoxTemplate, selector.SelectTemplate(new TestData(), null));

            Assert.IsFalse(selector.Items.IsFrozen);
            selector.Items.Add(new DXDataTemplateTrigger());
        }
Exemple #6
0
        public void NullBinding()
        {
            var selector = new DXDataTemplateSelector();

            selector.Items.Add(new DXDataTemplateTrigger()
            {
                Value    = "True",
                Template = TextBoxTemplate,
            });
            Assert.AreEqual(TextBoxTemplate, selector.SelectTemplate(new TestData()
            {
                String = ""
            }, null));
        }
Exemple #7
0
        public void DoNotListenINPCNotifications()
        {
            var selector = new DXDataTemplateSelector();

            selector.Items.Add(new DXDataTemplateTrigger()
            {
                Binding  = new Binding("Bool"),
                Value    = "True",
                Template = TextBoxTemplate,
            });
            var data = ViewModelSource.Create <TestData>();

            data.Bool = true;
            Assert.AreEqual(1, data.BoolGetCount);
            Assert.AreEqual(TextBoxTemplate, selector.SelectTemplate(data, null));
            Assert.AreEqual(2, data.BoolGetCount);

            data.Bool = false;
            DispatcherHelper.DoEvents();
            Assert.AreEqual(3, data.BoolGetCount);
            Assert.AreEqual(null, selector.SelectTemplate(data, null));
            Assert.AreEqual(4, data.BoolGetCount);
        }
Exemple #8
0
        public void DefaultTemplateFirst_UseLastDefaultTemplate()
        {
            var selector = new DXDataTemplateSelector();

            selector.Items.Add(new DXDataTemplateTrigger()
            {
                Template = CheckBoxTemplate,
            });
            selector.Items.Add(new DXDataTemplateTrigger()
            {
                Template = TextBoxTemplate,
            });
            Assert.AreEqual(TextBoxTemplate, selector.SelectTemplate(new TestData(), null));
        }
Exemple #9
0
        public void Freeze()
        {
            var selector = new DXDataTemplateSelector();

            selector.Items.Add(new DXDataTemplateTrigger()
            {
                Binding  = new Binding("Bool"),
                Value    = "True",
                Template = TextBoxTemplate,
            });
            Assert.AreEqual(TextBoxTemplate, selector.SelectTemplate(new TestData()
            {
                Bool = true
            }, null));


            Assert.Throws <InvalidOperationException>(() => selector.Items.Add(new DXDataTemplateTrigger()));
            Assert.Throws <InvalidOperationException>(() => selector.Items[0].Value    = null);
            Assert.Throws <InvalidOperationException>(() => selector.Items[0].Binding  = null);
            Assert.Throws <InvalidOperationException>(() => selector.Items[0].Template = null);
        }