1 0
post icon

Silverlight Tip of the Day #32 – BiDi – Bi-Directional Text

BiDi or Bi-directional text is text that flows right-to-left (RTL) and left-to-right (LTR). For example, while English flows left to right other languages such as Arabic, Hebrew and Persian scripts flow right to left. Chinese characters can also be written in either RTL or LTR directions.

Silverlight supports BiDi through a property called FlowDirection. This property can be set to either RightToLeft or the default LeftToRight.

The following code below demonstrates this property in action:

<TextBlock FlowDirection="RightToLeft" Text="نصائح Silverlight من اليوم"/>
<TextBlock FlowDirection="RightToLeft" Text="Silverlight 每日提示"/>
<TextBlock FlowDirection="LeftToRight" Text="Silverlight Tips of the Day"/>

 

The first two TextBlocks flow RTL and the last one flows LTR.

Demo:

Install Microsoft Silverlight

Note that this property can also be applied to other controls such as RichTextBox, ListBox, TextBox, etc.

Source: Tip32_BIDI.zip

Thanks,

–Mike

Leave a Comment
post icon

Silverlight Tip of the Day #31 – Pinning Full Screen Mode

Full screen can be toggled on and off via a user command such as a button click by setting the following property to true or false: Application.Current.Host.Content.IsFullScreen

Normally Silverlight applications will only stay in full screen mode until a user hits the <ESC> key or until the application loses focus. For example, if the user has multiple monitors and they click on another application in another monitor this will cause the Silverlight application to return to windowed mode. If you want to prevent your Silverlight application from leaving full screen mode in this case you can do so by setting:

Application.Current.Host.Content.FullScreenOptions = 
                 System.Windows.Interop.FullScreenOptions.StaysFullScreenWhenUnfocused;

 

Now, when a user clicks on another application in another monitor they will be prompted with the following dialog:

image

If the user clicks ‘Remember my answer’ and the “Yes” button they will only need to be prompted this one time.

In the following demo below I have added a button that toggles full screen mode as well as an event that will update the status text to show whether we are in full screen mode or not:

App.Current.Host.Content.FullScreenChanged += ((sender, args) =>
{
    if (App.Current.Host.Content.IsFullScreen)
    {
        ModeTB.Text = "Mode=Full Screen";
    }
    else
    {
        ModeTB.Text = "Mode=Windowed";
    }
});

 

Demo:

Install Microsoft Silverlight

Thanks,

–Mike

Leave a Comment
post icon

Silverlight Tip of the Day #30 – Sending Email from Silverlight

In this tip I will be showing you how to send an email via Silverlight. Obviously sending email directly from the Silverlight client is not possible.

However, as with most things, you can leverage a Silverlight-enabled WCF server to do the dirty work for you. In this steps below I will be showing you the code needed to send the email through the SmtpClient object as well as some minor configurations you need to do to your server to get it working.

Step #1. Create a new Silverlight application.

Step #2. In your web site, add a Silverlight-enabled WCF web service (calling it something like MyService.svc)

Step #3. Add the following method to your MyService.svc.cs file:

[OperationContract]
public bool SendMail(string emailTo, string emailFrom, string msgSubject, string msgBody)
{
    bool success = false;
 
    try
    {
        MailMessage msg = new MailMessage();
 
        msg.From = new MailAddress(emailFrom);
        msg.To.Add(new MailAddress(emailTo));
        msg.Subject = msgSubject;
        msg.Body = msgBody;
        msg.IsBodyHtml = true;
 
        SmtpClient smtp = new SmtpClient();
        smtp.Host = "111.111.111.111"; // Replace with your servers IP address
        smtp.Port = 25;
        smtp.EnableSsl = false;
        smtp.Send(msg);
        success = true;
    }
    catch
    {
        success = false;
    }
 
    return success;
}

 

Step #4: Build the web site

Step #5: In your Silverlight application, right click on Service Reference and choose Add Service Reference…

Step #6: Click the Discover button, choose your service under “Services” and click the OK button.

Step #7. At this point, in your Silverlight code, you can create a ServiceReference client and call the method directly like this:

ServiceReferenceTest.MyServiceClient client = new ServiceReferenceTest.MyServiceClient ();
 
client.SendMailAsynce(emailTo, emailFrom, msgSubject, msgBody);

 

Note that if you were to execute this code without first installing the SMTP Sever via IIS you would get a “Send Failed” exception.

Step #8: In your server open up the Server Manager (ServerManager.msc) and choose Add Features.

Step #9: Select SMTP Server and click Next until the install is complete.

At this point if you were to run the code you would get the following exception:

Mailbox unavailable. The server response was: 5.7.1 Unable to relay for…

Step #10: Open up IIS 6 Manager (not IIS Manager)

Step #11: Right click on SMTP Virtual Server and choose Properties.

Step #12: Under the Access tab, choose Authentication and verify Anonymous access is checked.

Step #13: Under the Access tab, click the “Relay” button and add the IP of your server  making certain the “Only the list below” button is checked.

At this point you should be good to go!

Thanks,

–Mike

Leave a Comment
post icon

Silverlight Tip of the Day #29 – Configuring Service Reference to Back to LocalHost

If your application leverages a Silverlight-enabled WCF service you may at times want to toggle the address to be pointing from the WCF service published and running on your server back to localhost in case you want to make modifications that you want to run and debug locally.

However, when pointing it back to localhost you might be stumped as to what port needs to be used. One easy way to determine this is to right click on your svc file in your web site, choose “Browse With”, select a browser and click the “Browse” button.

In your browser, copy the address from the address bar. This is the localhost address including the port you will want to configure your Silverlight service reference to point to. It will look like this:

http://localhost:21047/MyService.svc 

Thanks,
–Mike

Leave a Comment
post icon

Free CSS Training

If you are working on a web site that incorporates Silverlight you inevitably will need to do some level work with CSS (Cascading Style Sheets). If you are not too familiar with CSS you should jump on the opportunity to download and watch a free CSS training course which is only available for the next 2 days (until June 11th)! This is a 3  hour course broken up in a 8-part video series.

The series includes:

    • Introduction to CSS
    • CSS Selectors
    • Text Properties
    • Inheritance
    • The Cascade
    • What’s Next?

If you are interested, head over to:

http://www.sitepoint.com/blogs/2010/06/04/its-our-party-and-well-give-away-a-free-css-video-series-if-we-want-to/

or directly to:

http://www.sitepoint.com/videos/videocss1/

Thanks,
–Mike

Leave a Comment