Search code examples
c#silverlightvisual-studio-2012silverlight-5.0

Silverlight ChildWindow - Update label with textbox


I have very simple code in C# to present MessageBox:

MessageBox.Show("Hello Action!");

Now I need to do the following: to replace the MessageBox by a Silverlight ChildWindow element, Add a label, a button and a textbox and after that Pressing the button updates the label content with the textbox content.

How to do it? I did not find some example on the Net.

My full code is this:

namespace DevTrainingSilverlight2
{
    public class HelloAction : W6Action
    {
        public override void Initialize(W6ActionConfigSection configuration, UIElement containingControl, UIElement associatedControl)
        {
            base.Initialize(configuration, containingControl, associatedControl);
        }

        public override void UpdateState(System.Collections.IList selectedObjectsInFocus)
        {
            base.UpdateState(selectedObjectsInFocus);
        }

        public override void Invoke(System.Collections.IList selectedObjectsInFocus)
        {
            base.Invoke(selectedObjectsInFocus);
            MessageBox.Show("Hello Action!");
        }
    }
}

Solution

  • Add the Textbox and the Button to the childwindow in silverlight.

    And you can pass the content as a parameter while opening and update it like below.

     ChildWindowControl childControl = new ChildWindowControl(content);
     childControl.Show();
    

    and change the constructor of Childwindow as follows,

    public ChildWindowControl(string name)
     {
       InitializeComponent();
       this.lblValue = name;
     }