Esempio n. 1
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            var datacontext = new Person()
                {
                    Name = "O Monstro",
                    LastName = "Desmaisons",
                    Local = new Local() { City = "Florianopolis", Region = "SC" },
                    PersonalState = PersonalState.Married
                };

            _FirstSkill = new Skill() { Name = "Langage", Type = "French" };

            datacontext.Skills.Add(_FirstSkill);
            datacontext.Skills.Add(new Skill() { Name = "Info", Type = "C++" });

            Window w = sender as Window;
            w.DataContext = datacontext;
            _Person = datacontext;
        }
        public void Basic_Option_Simple_UsingRelativePath_AfterDataContext()
        {
            Test((c, w) =>
            {
                var mre = new ManualResetEvent(false);

                DisplayEvent de = null;
                EventHandler<DisplayEvent> ea = null;
                ea = (o, e) => { de = e; c.OnDisplay -= ea; };
                c.OnDisplay += ea;
                var dc = new Person();

                string relp = "javascript\\navigation_1.html";
                string path = string.Format("{0}\\{1}", typeof(HTMLViewControl).Assembly.GetPath(), relp);

                File.Copy("javascript\\navigation_1.html", path);

                string[] jvs = new string[] { "Ko_register.js", "Ko_Extension.js", "knockout.js" };

                string src = string.Format("{0}\\javascript\\src", typeof(HTMLViewControl).Assembly.GetPath());
                Directory.CreateDirectory(src);

                foreach (string jv in jvs)
                {
                    string p = string.Format("{0}\\javascript\\src\\{1}", typeof(HTMLViewControl).Assembly.GetPath(), jv);
                    if (!File.Exists(p))
                        File.Copy(string.Format("javascript\\src\\{0}", jv), p);
                }

                //<script src="src\knockout.js" type="text/javascript"></script>
                //<script src="src\Ko_Extension.js" type="text/javascript"></script>
                //<script src="src\Ko_register.js" type="text/javascript"></script>

                w.RunOnUIThread(() =>
                {
                    c.Mode = JavascriptBindingMode.OneWay; 
                    w.Window.DataContext = dc;
                    c.RelativeSource = relp;
                    mre.Set();
                });

                mre.WaitOne();

                Thread.Sleep(2000);
                foreach (string jv in jvs)
                {
                    string p = string.Format("{0}\\javascript\\src\\{1}", typeof(HTMLViewControl).Assembly.GetPath(), jv);
                    File.Delete(p);
                }
                File.Delete(path);
                de.Should().NotBeNull();
                de.DisplayedViewModel.Should().Be(dc);


            });
        }
        public void Basic_Option_Simple()
        {
            Test((c, w) =>
            {
                var mre = new ManualResetEvent(false);

                DisplayEvent de = null;
                EventHandler<DisplayEvent> ea = null;
                ea = (o, e) => { de = e; c.OnDisplay -= ea; };
                c.OnDisplay += ea;
                var dc = new Person();

                w.RunOnUIThread(() =>
                {
                    c.Mode = JavascriptBindingMode.OneWay;
                    string relp = "javascript\\navigation_1.html";
                    c.Uri = new Uri(string.Format("{0}\\{1}", Assembly.GetAssembly(typeof(Test_HTMLViewControl)).GetPath(), relp));
                    w.Window.DataContext = dc;
                    mre.Set();
                });

                mre.WaitOne();

                Thread.Sleep(1500);
                de.Should().NotBeNull();
                de.DisplayedViewModel.Should().Be(dc);


            });
        }