It takes a long time for us to load big data when developing Silverlight. To give users a good impression, let's give a loading prompt. Below I will simplyProgramPost it to help you
Waiting. XAML
<Usercontrol X: class = "example. Portal. Common. Waiting"
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"
MC: ignorable = "D"
Designwidth = "640" designheight = "480">
<Grid X: Name = "layoutroot" width = "Auto" Height = "Auto">
<Grid background = "black" opacity = "0.2"> </GRID>
& Lt; canvas width = "320" Height = "50" & gt;
<Rectangle radiusx = "8" radiusy = "8" stroke = "{X: NULL}" fill = "#19000000" Height = "49" width = "316" canvas. left = "6" canvas. top = "3"/>
<Rectangle radiusx = "8" radiusy = "8" stroke = "{X: NULL}" fill = "#19000000" Height = "48" width = "316" canvas. left = "5" canvas. top = "3"/>
<Border Height = "50" width = "320" background = "# ffffffff" borderbrush = "# ffacacac" borderthickness = "," cornerradius = "8, 8, 8">
<Rectangle radiusx = "8" radiusy = "8" stroke = "{X: NULL}" margin = "1, 1, 1">
<Rectangle. Fill>
<Lineargradientbrush endpoint = "0.5, 1" startpoint = "0.5, 0">
<Gradientstop color = "# ffffffff"/>
<Gradientstop color = "# ffe9e9e9" offset = "1"/>
</Lineargradientbrush>
</Rectangle. Fill>
</Rectangle>
</Border>
</Canvas>
<Grid width = "320" Height = "50" verticalalignment = "center">
<Grid. columndefinitions>
<Columndefinition width = "5 *"/>
<Columndefinition width = "10 *"/>
<Columndefinition width = "80 *"/>
<Columndefinition width = "5 *"/>
</Grid. columndefinitions>
<! --Waiting.png you can find an image -->
<Image stretch = "NONE" Source = "../resources/image/waiting.png" grid. Column = "1" opacity = "0.3"/>
<Image X: Name = "waitingimage" stretch = "NONE" Source = ".. /resources/image/waiting.png "grid. column = "1" rendertransformorigin = "0.5, 0.5">
<Image. rendertransform>
<Rotatetransform angle = "0"> </rotatetransform>
</Image. rendertransform>
</Image>
<Textblock X: Name = "titletext" fontfamily = "calibri" fontsize = "13" foreground = "# ff000000" horizontalalignment = "Left" grid. Column = "3"/>
<Textblock text = "waiting..." X: Name = "waitingtext"
Fontfamily = "verdana" fontsize = "14" verticalalignment = "center" horizontalalignment = "Left" grid. Column = "2"/>
</GRID>
</GRID>
<Usercontrol. Resources>
<Storyboard X: Name = "storyboard">
<Doubleanimation storyboard. targetname = "waitingimage" Duration = "0: 0. 7 "to =" 360 "storyboard. targetproperty = "(uielement. rendertransform ). rotatetransform. angle "repeatbehavior =" forever "> </doubleanimation>
<Doubleanimationusingkeyframes storyboard. targetname = "waitingtext" storyboard. targetproperty = "opacity" repeatbehavior = "forever">
<Splinedoublekeyframe keytime = "00:00:0. 0" value = "0"/>
<Splinedoublekeyframe keytime = "00:00:0. 5" value = "1"/>
<Splinedoublekeyframe keytime = "00:00:1. 0" value = "0"/>
</Doubleanimationusingkeyframes>
</Storyboard>
</Usercontrol. Resources>
</Usercontrol>
Waiting. CS
Using system. Windows. controls;
Namespace example. Portal. Common
{
Public partial class waiting: usercontrol
{
Public waiting ()
{
Initializecomponent ();
This. storyboard. Begin ();
}
/// <Summary>
/// Title
/// </Summary>
Public String title
{
Get {return this. titletext. Text ;}
Set {This. titletext. Text = value ;}
}
Public void setloadingtext (string text)
{
This. waitingtext. Text = text;
}
Public void setloadingtext ()
{
This. waitingtext. Text = "processing. Please wait ......";
}
}
}
Next, let's define another class, external interface, and then directly call this class.
Window. CS
Using system;
Using system. windows;
Using system. Windows. controls;
Namespace example. Portal. Common
{
Public class windows
{
Private Static waiting;
Private Static string waitingname = "Waiting ";
Static windows ()
{
If (waiting = NULL)
{
// Obtain the main application interface
Usercontrol rootpage = application. Current. rootvisual as usercontrol;
If (rootpage! = NULL)
{
// Obtain the waiting node in the application interface
Waiting = rootpage. findname (waitingname) as waiting;
}
}
}
/// <Summary>
/// Display the waiting Information
/// </Summary>
/// <Param name = "message"> </param>
Public static void showwaiting (string message)
{
Try
{
If (waiting! = NULL)
{
Waiting. Dispatcher. begininvoke () =>
{
Waiting. Visibility = visibility. visible;
Waiting. setloadingtext (Message );
});
}
}
Catch (exception E)
{
String STR = E. Message. tostring ();
}
}
/// <Summary>
/// Display the waiting Information
/// </Summary>
Public static void showwaiting ()
{
Try
{
If (waiting! = NULL)
{
Waiting. Dispatcher. begininvoke () =>
{
Waiting. Visibility = visibility. visible;
Waiting. setloadingtext ();
});
}
}
Catch (exception E)
{
String STR = E. Message. tostring ();
}
}
/// <Summary>
/// Hide the waiting Information
/// </Summary>
Public static void hidewaiting ()
{
If (waiting! = NULL)
Waiting. Dispatcher. begininvoke () => waiting. Visibility = visibility. Collapsed );
}
}
}
After writing the above, you cannot use it directly. If you are using it now, you cannot display the waiting information. You must add it in the program set.Code(Usually in index. XAML)
Xmlns: Local = "CLR-namespace: hieg2.portal. Common; Assembly = hieg2.portal. Common"
<Grid X: Name = "loadinggrid">
<Local: Waiting X: Name = "Waiting" visibility = "Collapsed"/>
</GRID>
After setting the preceding settings, you can use it directly. For example, if you want to load a large data file, you can directly use it as follows:
Windows. showwaiting ();
// Write the loaded code. If you use asynchronous loading, you must note the following before hiding the data after it is loaded.
Windows. hidewaiting ();
You have limited capabilities. You can use your talents to make it better.