开发者

Silverlight getting opened site

Let's say I have a MainPage that has a button. I also have another page(Page2) that has a textbox. I woud like to add a simple text "TEXT" to the textbox in Page2 while navigating by the button from MainPage. I have a problem with getting actually opened Site. In Windows Forms appl开发者_如何学JAVAications it is solved by:

Page2 page2 = (Page2)Application.OpenedForms["Page2"]; page2.TextBox.Text = "TEXT";

How can i do it in Silverlight? HELP")


I don't have a development environment handy, so my apologies for this being non-exact but this method should work for you and is the preferred way for me to do something like this.

Here is my understanding of the hierarchy using pseudo code markup:

<Page2>
    <Textbox ID="MyTextbox" />
    <Control ID="Page1">
        <Button ID="MyButton" />
    </Control>
</Page2>

With this understanding, it sounds like what you need to do is inject a handle to your TextBox into a property on your lower-level control:

// Page1 code
public TextBox TextboxToUpdateWhenYouPressTheButton { get; set; }

Click()
{
    // Perform Not Null Check and handle it somehow if it is null.

    // Set the text.
    TextboxToUpdateWhenYouPressTheButton.Text = "This is the text that goes into the textbox.";
}

Doing it this way, whenever you create your Page1, simply pass in a handle for your textbox into the new TextboxToUpdateWhenYouPressTheButton property on your inner control. Ultimately, the idea stays the same, we only access it via this property instead of directly now. This will allow your control to be used on many screens regardless of what the textbox is called. This way, for your page to "consume" the control, there is the requirement that it "registers" this textbox first.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜