In this post we will learn how to create a user defined message box control in Silverlight 3. So that, you can use it in any Silverlight application instead of the default messagebox.
Creating the MessageBox child window user control:
At first we will create our own user control. Then we will use it in a sample application. Start Expression Blend and choose Control library project template (in order to generate a DLL so that it can be added to in any Silverlight application), then remove the MainPage.xaml from your solution and add a new Child Window.
In expression blend, now you can easily change the appearance of this child window. You can change the information bar back ground, change the whole layout, the power is on your hand. How to beautify it is up to you, I will not discuss about that in this post. For this demo, I removed all the default assets and included the followings in the layout root of the child window:
<StackPanel Height="23" HorizontalAlignment="Right" VerticalAlignment="Bottom" Orientation="Horizontal">
<Button x:Name="btnYes" Content="Cancel" Click="CancelButton_Click" Width="75" Height="23"
/>
<Button x:Name="btnNo" Content="OK" Click="OKButton_Click" Width="75" Height="23"
/>
<Button x:Name="btnCancel" Width="75" Content="Button"/>
</StackPanel>
<TextBlock x:Name="txtMsg" Text="TextBlock" TextWrapping="Wrap" Margin="155,51,8,87"/>
<Image x:Name="imgIcon" HorizontalAlignment="Left" Width="100" Margin="8,66,0,99"/>
Now in the code delete all the default things.Now my requirement was to show four types of information : question,warning,error message and general information. Also I had to show relative icons in the left hand side of the box too. So in the code I added the followings:
Zorayr KhalapyanPosted Jan 23, 2011, 4:56 AM
For already implemented message boxes (info, error, confirm, text input, combo input, etc) check out http://silverlightmsgbox.codeplex.com/. It's pretty easy to utilize and extend. Have fun!
Apu GhoshPosted Dec 28, 2010, 5:47 AM
THANKS A LOT ...................... BRO. good job