Exemple #1
0
        public void VSM_CustomVisualStateManager()
        {
            var myControl2 = new MyControl2();

            var prop1Default = (double)InnerControl.Property1Property.GetMetadata(myControl2.InnerControl.GetType()).DefaultValue;
            var prop2Default = (double)InnerControl.Property2Property.GetMetadata(myControl2.InnerControl.GetType()).DefaultValue;
            var prop3Default = (double)InnerControl.Property3Property.GetMetadata(myControl2.InnerControl.GetType()).DefaultValue;
            var prop4Default = (double)InnerControl.Property4Property.GetMetadata(myControl2.InnerControl.GetType()).DefaultValue;

            myControl2.InnerControl.Property1.Should().Be(prop1Default);
            myControl2.InnerControl.Property2.Should().Be(prop2Default);
            myControl2.InnerControl.Property3.Should().Be(prop3Default);
            myControl2.InnerControl.Property4.Should().Be(prop4Default);
            myControl2.InnerControl.CurrentState.Should().BeNull();

            myControl2.GoToState1().Should().BeTrue();

            myControl2.InnerControl.Property1.Should().Be(prop1Default);
            myControl2.InnerControl.Property2.Should().Be(prop2Default);
            myControl2.InnerControl.Property3.Should().Be(prop3Default);
            myControl2.InnerControl.Property4.Should().Be(prop4Default);
            myControl2.InnerControl.CurrentState.Should().Be("state1");

            myControl2.GoToState2().Should().BeTrue();

            myControl2.InnerControl.Property1.Should().Be(prop1Default);
            myControl2.InnerControl.Property2.Should().Be(prop2Default);
            myControl2.InnerControl.Property3.Should().Be(prop3Default);
            myControl2.InnerControl.Property4.Should().Be(prop4Default);
            myControl2.InnerControl.CurrentState.Should().Be("state2");

            myControl2.GoToState3().Should().BeTrue();

            myControl2.InnerControl.Property1.Should().Be(prop1Default);
            myControl2.InnerControl.Property2.Should().Be(prop2Default);
            myControl2.InnerControl.Property3.Should().Be(prop3Default);
            myControl2.InnerControl.Property4.Should().Be(prop4Default);
            myControl2.InnerControl.CurrentState.Should().Be("state3");

            myControl2.GoToState4().Should().BeTrue();

            myControl2.InnerControl.Property1.Should().Be(prop1Default);
            myControl2.InnerControl.Property2.Should().Be(prop2Default);
            myControl2.InnerControl.Property3.Should().Be(prop3Default);
            myControl2.InnerControl.Property4.Should().Be(prop4Default);
            myControl2.InnerControl.CurrentState.Should().Be("state4");

            VisualStateManager.GoToState(myControl2, "some_state_that_does_not_exist", false).Should().BeFalse();

            myControl2.InnerControl.Property1.Should().Be(prop1Default);
            myControl2.InnerControl.Property2.Should().Be(prop2Default);
            myControl2.InnerControl.Property3.Should().Be(prop3Default);
            myControl2.InnerControl.Property4.Should().Be(prop4Default);
            myControl2.InnerControl.CurrentState.Should().BeNull();
        }
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.myControl1 = new EventBrokerPattern.MyControl1();
            this.myControl2 = new EventBrokerPattern.MyControl2();
            this.myControl3 = new EventBrokerPattern.MyControl3();
            this.SuspendLayout();
            // 
            // myControl1
            // 
            this.myControl1.Location = new System.Drawing.Point(12, 12);
            this.myControl1.Name = "myControl1";
            this.myControl1.Size = new System.Drawing.Size(152, 86);
            this.myControl1.TabIndex = 0;
            // 
            // myControl2
            // 
            this.myControl2.Location = new System.Drawing.Point(184, 58);
            this.myControl2.Name = "myControl2";
            this.myControl2.Size = new System.Drawing.Size(131, 28);
            this.myControl2.TabIndex = 1;
            // 
            // myControl3
            // 
            this.myControl3.Location = new System.Drawing.Point(184, 24);
            this.myControl3.Name = "myControl3";
            this.myControl3.Size = new System.Drawing.Size(131, 28);
            this.myControl3.TabIndex = 2;
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(327, 110);
            this.Controls.Add(this.myControl1);
            this.Controls.Add(this.myControl2);
            this.Controls.Add(this.myControl3);
            this.Name = "Form1";
            this.Text = "Form1";
            this.ResumeLayout(false);

        }