Custom childwindow. Multiple custom windows are displayed at the same time.

Source: Internet
Author: User
The childwindow in SL cannot bring up two or more at the same time. We developed our own childwindow to solve similar obstacles.

 

Effect:


XAML:

 

< Usercontrol X: Class = "Slchindwindow. scselfcontrol"
Xmlns = "Http://schemas.microsoft.com/winfx/2006/xaml/presentation"
Xmlns: x = "Http://schemas.microsoft.com/winfx/2006/xaml"
Xmlns: d = "Http://schemas.microsoft.com/expression/blend/2008"
Xmlns: MC = "Http://schemas.openxmlformats.org/markup-compatibility/2006" Width = "592" Height = "511" Mouseleftbuttondown = "Usercontrol_mouseleftbuttondown" >
< Canvas Name = "Carrier" >
< Canvas Height = "43" Name = "Head" Width = "592" Mouseleftbuttondown = "Head_mouseleftbuttondown" Mousemove = "Head_mousemove" Mouseleftbuttonup = "Head_mouseleftbuttonup" >
< Image Canvas. Left = "554" Canvas. Top = "2" Height = "16" Name = "Btnclose" Width = "35" Source = "/Slchindwindow; component/images/close.jpg" Mouseleftbuttondown = "Btnclose_mouseleftbuttondown" />
</ Canvas >
< Canvas Height = "468" Name = "Body" Width = "592" >
< Image Height = "12" Name = "Resizer" Width = "10" Source = "/Slchindwindow; component/images/resizer.jpg" Canvas. Left = "582" Canvas. Top = "499" Mouseleftbuttondown = "Resizer_mouseleftbuttondown" Mouseleftbuttonup = "Resizer_mouseleftbuttonup" Mousemove = "Resizer_mousemove"   />
</ Canvas >
</ Canvas >
</ Usercontrol >

Corresponding background file:

 

Using System;
Using System. Collections. Generic;
Using System. LINQ;
Using System. net;
Using System. windows;
Using System. Windows. controls;
Using System. Windows. documents;
Using System. Windows. input;
Using System. Windows. Media;
Using System. Windows. Media. animation;
Using System. Windows. shapes;
Using System. Windows. Media. imaging;

NamespaceSlchindwindow
{
Public Partial ClassScselfcontrol: usercontrol
{
BoolIsmousecaptured =False;

Point clickpoint =NewPoint ();

PublicScselfcontrol ()
{
Initializecomponent ();
Initcontrol ();
}

Private Void Initcontrol ()
{
Image headbg = New Image ();
Headbg. Source = New Bitmapimage ( New Uri ( @" /Images/head.jpg " , Urikind. Relative ));
Headbg. width = 592 ;
Headbg. Height = 43 ;
Canvas. setleft (headbg, 0 );
Canvas. settop (headbg, 0 );
Canvas. setzindex (headbg ,- 1 );
Head. Children. Add (headbg );

Image bodybg = New Image ();
Bodybg. Source = New Bitmapimage ( New Uri ( @" /Images/body.jpg " , Urikind. Relative ));
Bodybg. width = 592 ;
Bodybg. Height = 468 ;
Canvas. setleft (bodybg, 0 );
Canvas. settop (bodybg, 43 );
Canvas. setzindex (bodybg ,- 1 );
Body. Children. Add (bodybg );

}

Private VoidHead_mouseleftbuttondown (ObjectSender, mousebuttoneventargs E)
{
Head. capturemouse ();
Ismousecaptured =True;
Clickpoint = E. getposition (senderAsUielement );
}

Private Void Head_mousemove ( Object Sender, mouseeventargs E)
{
If (Ismousecaptured)
{
If (Application. Current! = Null & Amp; application. Current. rootvisual! = Null &&
(E. getposition (application. Current. rootvisual). x < 0 | E. getposition (application. Current. rootvisual). Y < 0 ))
{
Return ; // If the content area of Silverlight is exceeded, return directly
}

Transformgroup =This. RendertransformAsTransformgroup;

If (transformgroup = null )
{< br> transformgroup = New transformgroup ();
}

translatetransform T = New translatetransform ()
{< br> X = E. getposition ( This ). x- This . clickpoint. x,
Y = E. getposition ( This ). y- This . clickpoint. Y
};

If (Transformgroup! = Null )
{
Transformgroup. Children. Add (t );
This . Rendertransform = transformgroup;
}

}
}

Private VoidHead_mouseleftbuttonup (ObjectSender, mousebuttoneventargs E)
{
Head. releasemousecapture ();
Ismousecaptured =False;
}

Static IntZ;

Private VoidUsercontrol_mouseleftbuttondown (ObjectSender, mousebuttoneventargs E)
{
Z ++;
Canvas. setzindex (This, Z );
}

///   <Summary>
/// Close
///   </Summary>
///   <Param name = "sender"> </param>
///   <Param name = "E"> </param>
Private Void Btnclose_mouseleftbuttondown ( Object Sender, mousebuttoneventargs E)
{
Canvas container = This . Parent As Canvas;
Container. Children. Remove ( This );
}

private void resizer_mouseleftbuttondown ( Object sender, mousebuttoneventargs E)
{< br> resizer. capturemouse ();
ismousecaptured = true ;
clickpoint = E. getposition (sender as uielement);
}

Private VoidResizer_mouseleftbuttonup (ObjectSender, mousebuttoneventargs E)
{
Resizer. releasemousecapture ();
Ismousecaptured =False;
}

Private Void Resizer_mousemove ( Object Sender, mouseeventargs E)
{
If (Ismousecaptured)
{
If (Application. Current! = Null & Amp; application. Current. rootvisual! = Null &&
(E. getposition (application. Current. rootvisual). x < 0 | E. getposition (application. Current. rootvisual). Y < 0 ))
{
Return ; // If the content area of Silverlight is exceeded, return directly
}

Transformgroup = This . Rendertransform As Transformgroup;
If (Transformgroup = Null )
{
Transformgroup = New Transformgroup ();
}
Scaletransform T = New Scaletransform ()
{
Scalex = (E. getposition ( This ). X- This . Clickpoint. X )/ This . Width, // To obtain the magnification.
Scaley = (E. getposition ( This ). Y- This . Clickpoint. Y )/ This . Height
};
If (Transformgroup! = Null )
{
Transformgroup. Children. Add (t );
This . Rendertransform = transformgroup;
}


}
}
}
}

 

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.