How to switch, call, or bring up or pass parameters between multiple XAML in Silverlight

Source: Internet
Author: User
There are no flash scenarios in Silverlight, and some are only XAML files. If you want to, you can also regard it as a "scenario" or "window". When you first started to contact SL, it is difficult to switch, call, and pass parameters between multiple XAML statements. Below are some methods I have summarized:

1. A. XAML jump to B. XAML

(A) First define a public interface, as shown below:

Using system. windows;

Namespace childwin. Code
{
Public interface icontent
{
Uielement content {Get; set ;}
}
}

(B) Both A. XAML and B. XAML implement this interface,CodeAs follows:

Public partial class A: usercontrol, icontent
{
...

//


// implement the icontent interface
///
Public new uielement content
{< BR> Get
{< br> return base. content;
}< br> set
{< br> base. content = value;
}< BR >}

Public partial class B: usercontrol, icontent
{
...
/// <Summary>
/// Implement the icontent Interface
/// </Summary>
Public new uielement content
{
Get
{
Return base. content;
}
Set
{
Base. content = value;
}
}}

(C) The place to jump, such as the following:

Private void btnchange_click (Object sender, system. Windows. routedeventargs E)
{
(App. Current. rootvisual as icontent). content = new window2 ();}

The above indicates that after the btnchange button is clicked, the current "scenario" will be switched to the "scenario" corresponding to window2.xaml"

2. Load "sub-XAML" in "primary XAML" (similar to the MDI window in software)

This is relatively easy. Place a container-class control (such as scrollviewer) in the main XAML and specify the content. refer to the following code:

<Scrollviewer X: Name = "viewer1" canvas. Top = "40" width = "400" Height = "258"> </scrollviewer>
...
Private void btnload_click (Object sender, system. Windows. routedeventargs E)
{
If (this. viewer1.content = NULL)
{
This. viewer1.content = new subwin ();
}}

3. "subxaml" is displayed in a modal window in "primary XAML"

This requires the childwindow control in sl3.0.

(A) Add a reference to system. Windows. Controls in the project.

(B) Add two lines of code to the XAML file header:

Xmlns: Controls = "CLR-namespace: system. Windows. controls; Assembly = system. Windows. Controls"
Xmlns: VSM = "CLR-namespace: system. Windows; Assembly = system. Windows"

(C) refer to the following code for the pop-up:

Private void btnshow_click (Object sender, system. Windows. routedeventargs E)
{
Childwindow win = new childwindow ();
Win. Title = "test pop-up window ";
Win. content = new subwin ();
Win. hasclosebutton = true;
Win. overlaybrush = new solidcolorbrush (colors. Gray );
Win. overlayopacity = 0.3;
Win. width = 205;
Win. Height = 205;
Win. Show ();
}

4. parameter passing when calling XAML

The constructor can be used to solve the problem. refer to the following code:
Namespace childwin
{
Public partial class subwin: usercontrol
{
Public subwin ()
{
Initializecomponent ();
}

Public subwin (datetime DT): this ()
{
This. calendar1.displaydate = DT;
}}
}

Here I have added a framework function with parameters for testing, that is, public subwin (datetime DT): this (). Here we accept a datetime parameter, then, set the display value of the date control to this parameter. The function of this () is to call a constructor without parameters, that is, subwin (), in this example, the medium price is:

Public subwin (datetime DT)
{
Initializecomponent ();
This. calendar1.displaydate = DT;
}

Note: When calling this XAML, the above statements are handled by xxx = new subwin (). Now we can use this. viewer1.content = new subwin (datetime. parse ("1979-6-5"); to pass a parameter to subwin

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.