Featured Posts

VS2010+SL3VS2010 beta + Silverlight 3 It keeps showing "Unable to Start Debugging. The Silverlight managed debugging package isn't installed".Finally the problem can be solved by installing Developer Runtime.

Readmore

An image in a post Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Quisque sed felis. Aliquam sit amet felis. Mauris semper, velit semper laoreet dictum, quam diam dictum urna, nec...

Readmore

Cash-Out Refinance For many, their homes are just not dwellings that protect them against rain, sun, and wind. But they are piggy banks, which can be used to raise some urgent money, even if...

Readmore

Saturday, November 15, 2008

4
We can live without Motion Path

For Silverlight, many agree it is not perfect enough coz it doesnt include many features that inside WPF. Well, as we all know, Silverlight is an engine for us to create a web-based program/application. In my opinion, being a web-based application, it should be lite but not simple of course. As I remember, last week, someone ask how to create a motion path in Silverlight in order to make a picture flying around an ellipse (circular motion). Yesterday, another post has been created where people keep on discussing the problem of silverlight without motion path.

I think all we can do is to relate Math and Programming together.
Fortunately, my PureMath teacher has taught about a set of parametric equations which declare a path of circle. Then I try to implement it on Silverlight. Finally, it works, and I my extremely happy with that. Here is the solution.

XAML

[sourcecode language='xml']




[/sourcecode]

...

[sourcecode language='xml']














[/sourcecode]

C#:

[sourcecode language='csharp'] int t = 0;
double AniX;
double AniY;

void Page_Loaded(object sender, RoutedEventArgs e)
{
Ellipse_ani_X.From = Ellipse_ani_Y.From = 0;
Ellipse_ani_Y.To = Ellipse_ani_X.To = AniX = AniY = 0;
t++;
myStory_Ellipse.Begin();
}

private void Ellipse_ani_X_Completed(object sender, EventArgs e)
{
myStory_Ellipse.Stop();
Ellipse_ani_X.From = AniX;
Ellipse_ani_X.To= AniX = Math.Cos(t * Math.PI / 50 ) * 100;
Ellipse_ani_Y.From = AniY;
Ellipse_ani_Y.To = AniY = Math.Sin(t * Math.PI / 50 ) * 100;
t++;
myStory_Ellipse.Begin();

}

private void Ellipse_ani_Y_Completed(object sender, EventArgs e)
{

}[/sourcecode]

I am trying to work out the motion path solution. I hope it will help all of you.

Regards,
Steve Wong(Hong Kong)
Live with Light!

0
Testing

Sunday, August 3, 2008

2
Come Back From GreenGourney

GREEN JOURNEY

Great Journey! meet lots of friends. As I have only joined the HK stop, there is still someone I dont know!
They are so nice, especially for the GuangDong ,Cheng Du, India, and of course HK! =]

Such a chance to meet people from lots of different countries is very rare in our life.
For me, although I was not participating so much in the trip, only the HK one, I miss those guys!

Thursday, July 17, 2008

1
Standard call to begin StoryBoard

This is a good remind from Yi-Lun Luo(MSFT) from Silverlight Official Forum
Hello, thanks for reporting this issue. I've verified the behavior and notified out product team. The issue appears to be: If you use Storyboard.SetTarget to set the target for an animation, if the property path is quite complex, the target will be lost after you begin the Storyboard. If you manually set the target before each Storyboard begins, it will work fine:

Storyboard.SetTarget(s1.Children(0), recMain)
s1.Begin()

Also you can use SetTargetName instead of SetTarget. If your objects are dynamically created, you can write something like this:

recMain.SetValue(FrameworkElement.NameProperty, "rec")
Storyboard.SetTargetName(d, "rec")

Yes [Y]Yes [Y]Yes [Y]Yes [Y]Yes [Y]Yes [Y]

Friday, July 11, 2008

1
MIX 08 HongKong

After participating MIX Essentials 08.. I got a book ahha But it is quite similar to the last edition introducing Silverlight 1.0



Well, today I met Harris Andy and Angela I knew them coz they are the judges of ImagineCup local

But they are not the main point. The most important is the content. It's very well. Awesome!
Especially the video talking about how Microsoft technologies get around in our lives! Well Done! I should try hard to find that video =]

By the way the examples shown today are good and some of them include good ideas.

All in all, Wonderful! Well, I should work hard and try to get into Microsoft haha(daydreaming again!)

1
Months after Imagine Cup 08

Well, after paticipating Imagine Cup 08 I learnt a lot.

Working with 3 other schoolmates, Chung, Peter and Timothy, they have their own expertise... And we continue to implement our work in C#. Newly adding Windows Communication Foundation (WCF) and Silverlight, I take up the role to learn Silverlight and Peter responsible for the WCF. Our project seems to be very good together with our good idea and the new technology. It does consume most of my time. I sepnt a day to read the Introducing Microsoft Silverlight 1.0 from Lawrence Moroney and spent a week to read the Developing Windows-Based Applications with Visual C#.NET. I think it should be a miracle coz I am just a secondary student now. =]

After knowing all the foundation of Silverlight and C# I started making the WebPage I was responisble for. It is extremely difficult for me to handle this new technology Silverlight 2.0, luckily I did some project using Flash and know some algorithm DFS BFS... etc They should take some advantage for me.

When all of us think our project is very poor at least worse than last year's one, the judges from Microsoft said, "oh quite good" ... and they came forward to have a look on the RFID Card and Receiver. We are surprised ... shocked ...

When we entered the final in Local, we meet our rival using lots of new technologies including GPS... UMPC ...EeePC etc well and a home-made Carbon Dioxide meter (I think that's not made by them ahha)

Finally, we got 2nd.. I know we had all done very well, especially Thanks for Angela Ip =]

It gives me so much experience in Computer Programming and since then I started answering question on SIlverlight forum. That's worth !Not only does it earn points (that's very minor for me) but also let me know how much I know now. It is just like a chapter checkpoint. People having different kinds of question and ask in the forum just like some guys who are giving me a Test with many different chapter in a big subject SILVERLIGHT =]

I think we should treasure the chance to learn and the chance to compete!

By the way, my academic result is having the trend of dorpping down... /.\ so I must work hard!

Thursday, July 10, 2008

3
To Do List

Well, I have quite a bit to do these days becoz I want to try as much as I can in this Summer Holiday

Of course I will have some time for my academic preparation

Things to do are as follow, and I have no idea for each item at all. If you do have, please tell me or kindly comment here

  1. Prepare for the ImagineCup2009 (think of the toughest question that we are facing now)

  2. Linking Windows LiveID Authentication and Silverlight together

  3. create a useful little silverlight application (theme hasnt been decided)

  4. take a deep look into working ADO.NET with Silverlight (know quite a little bit)

  5. learn more about PopFly (I know nothing about it)

  6. Create a game on Silverlight(the least priority)

  7. To be a MVP (daydreaming...)


Hopefully, I can do much much...better than now after a few year... Fortunately, I am just 17 years old now =] still have a few of time

Steve Wong (Hong Kong)
Live with Light

Tuesday, July 1, 2008

2
Tired and...

Spending lots of time on silverlight.net. Actually, not too much, but it is sure consuming some of my time. Now, I cant decide what to create.. I want to make a software but I have no idea at all. I wrote a mail sender before coz it is useful for me at least. Now, I would like to do more on the ADO.NET coz it should be something very important for the one who works with WebService.

By the way, these days, I replied some posts and found that many posts are related to 404 Error throws from the WebService when working with Silverlight. Not only does it the CrossDomain Error but also size of Data being transfered and the endpoint address. And the one who are having the problem right now please do search on a good search engine, and you should find lots of articles about 404 from silverlight.net/foums.

I should take enough rest before working on my new project .. topic is still not yet decided

Hopefully, all things go straight.

Live with Light!

SteveWong
(HongKong)

Tuesday, June 24, 2008

3
Finished a little app

I made a mail sender in Silverlight and it have the moderation on the attachments and allow people to send an e-mail with CC BCC even though they dont have an email account

Check out here

Monday, June 16, 2008

1
BUSY With Exams

I am having my school exam right now. So I may have to leave away from my computer for two weeks...

These days, I cant answer questions on Silverlight.Net although my answers may not be so accurate.

I am looking forward to the end of the exam and also the MIX 2008 Essential =]

Monday, June 9, 2008

0
Silverlight Beta 2

Still a long way to go...

After upgraded to Silverlight 2 beta 2, it seems that there is so many problems...

  1. Listbox.Items.MouseLeftButtonDown Event cannot be fired 

  2. WCFService cannot be added as Service Reference

  3. Beta 2 Runtime cannot view Beta 1 Application

  4. .... Still more to be found and discovered..


These are not my main point. What I want to say is that - it is still a Beta Version, isn't it?

Engineers from Microsoft are still trying their best to create the best environment for us to build such a Dynamic Scenario (Silverlight). 

Please Clap for them and give your opinion at http://www.silverlight.net/forums/ and post the bugs you found onto it.

Thanks!

Live with Light!
Steve Wong (Hong Kong) 

Friday, June 6, 2008

0
Silverlight Beta 2 has released

http://silverlight.net/forums/t/17337.aspx

Newly Updated!

  • Important! Migrating Older Code to the Newer Release

  • Update Silverlight.js

  • Sockets Breaking Change

  • Change for Built-In Style of Controls

  • MIME Type and Installer URL Change

  • SetTargetProperty and GetTargetProperty Changes

  • System.Windows.Control.dll Merged with System.Windows.dll

  • ToolTip Changes

  • Removed Several Properties from Controls in System.Windows*dll

  • Change in Handling of System.Windows.Controls.Extended.dll in XAML

  • Changes to HtmlElement.GetAttribute and HtmlElement.GetProperty

  • Calendar/DatePicker Changes

  • HtmlPage.UnregisterScriptableObject Removed

  • WebClient and HttpWebRequest Changes

  • Improved Null Argument Checking in System.Xml

  • BackgroundWorker Moved

  • Deep Zoom Image and Collections Format Change

  • MultiScaleImage Change

  • AllowInboundCallsFromXDomain Changes

  • Changes to Scroll-related APIs and Drag*EventArgs

  • Glyphs Element Requires Either UniCodeString or Indices Attribute

  • ItemsControl.Items Is Now of Type ItemCollection Instead of IList

  • RoutedEventArgs.Handled=true Events No Longer Bubble

  • Style Cannot Be Applied to Control That Is Incompatible with Its TargetType

  • SetValue Only Accepts the Correct Types (No Conversions)

  • Control.InitializeFromXaml Removed

  • No Longer Can Specify Name and x:Name on the Same Element

  • Changes to Cross-Domain Policy

  • Storyboards Can Be Active While Outside the Live Tree

  • GetValue on Storyboard.Duration Only Returns Storyboard.Duration

  • Image and ImageBrush Class Changes

  • TextBox Template Changes

  • Custom BorderBrush/BorderThickness Change

  • ButtonBase Changes

  • ListBox and ListBoxItem Changes

  • ContentControl and ContentPresenter Changes

  • GetValue Changes

  • Updates to Control Styles

  • Miscellaneous API Changes




 

Thursday, June 5, 2008

0
Keyboard OSK Control

WOW. It seems that most of my posts are written because I got ideas while I was answering the question on Silverlight.Net.

Today, I would like to introduce my OSK but it is only done very simply.
It doesnt support NumLk ScrLk Shift CapLk those function keys....
In other words, it support mainly input of words.

Let me paste the code here for all of you.

Page.xaml.cs

using System;
using System.Collections.Generic;
using System.Linq;
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;
using System.Windows.Markup;
using System.ComponentModel;

namespace Testing
{
public partial class Page : UserControl
{
string[] keystring = new string[49] { "`", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-", "=", "<", "Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "[", "]", "\\", "A", "S", "D", "F", "G", "H", "J", "K", "L", ";", "'", "Z", "X", "C", "V", "B", "N", "M", ",", ".", "?", " " };

public Page()
{
InitializeComponent();
Loaded += new RoutedEventHandler(Page_Loaded);
}

public void Page_Loaded(object sender, RoutedEventArgs e)
{
for (int i = 0; i <= 48; i++)
{
Button k = new Button();
k.Content = keystring[i];
k.Width = 20; k.Height = 20;
if (i == 48 )
{
k.Width = 220;
k.Margin = new Thickness(-30, 80, 0, 0);
}
else if (i >= 38 )
{
k.Margin = new Thickness((i-38 ) * 20 - 20, 60, 180 -((i-38 ) * 20 - 20), 20);
}
else if (i >= 27)
{
k.Margin = new Thickness((i-27) * 20 - 30, 40, 180 - ((i-27) * 20 - 30), 40);
}
else if (i >= 14)
{
k.Margin = new Thickness((i - 14) * 20 - 40 , 20, 180 - ((i - 14) * 20 - 40), 60);
}
else
{
k.Margin = new Thickness(i * 20 - 50, 0, 180 - i * 20 + 50, 80);
}
KeyBoard.Children.Add(k);
k.Click += new RoutedEventHandler(k_Click);
}
}

void k_Click(object sender, RoutedEventArgs e)
{
Button temp = sender as Button;
if (temp.Content.ToString() == "<" )
{
if (tb.Text.Length != 0)
{
tb.Text = tb.Text.Remove(tb.Text.Length - 1, 1);
}
}
else
{
tb.Text += temp.Content.ToString();
}
}
#region Drag and Drop Starts Here
private bool isMouseCaptured;
private Point mousePosition;

void DragNDrop_MouseMove(object sender, MouseEventArgs e)
{
FrameworkElement item = sender as FrameworkElement;
if (isMouseCaptured)
{
// Calculate the current position of the object.
double deltaV = e.GetPosition(null).Y - mousePosition.Y;
double deltaH = e.GetPosition(null).X - mousePosition.X;
double newTop = deltaV + (double)KeyBoard.GetValue(Canvas.TopProperty);
double newLeft = deltaH + (double)KeyBoard.GetValue(Canvas.LeftProperty);
// Set new position of object.
KeyBoard.SetValue(Canvas.TopProperty, newTop);
KeyBoard.SetValue(Canvas.LeftProperty, newLeft);
// Update position global variables.
mousePosition = e.GetPosition(null);
}
}

void DragNDrop_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
FrameworkElement item = sender as FrameworkElement;
isMouseCaptured = false;
item.ReleaseMouseCapture();
mousePosition.X = mousePosition.Y = 0;
item.Cursor = null;
item.Opacity *= 2;
}

void DragNDrop_MouseEnter(object sender, MouseButtonEventArgs e)
{
FrameworkElement item = sender as FrameworkElement;
mousePosition = e.GetPosition(null);
isMouseCaptured = true;
item.CaptureMouse();
item.Opacity *= 0.5;
}
#endregion Drag and Drop Starts Here
}
}



One for remind, the osk can move actually with the Drag and Drop code inside code-behind.


Live With Light!
SteveWong (Hong Kong)

Wednesday, June 4, 2008

0
Powerful XAML

Today, I answered a question which is about XamlReader. By the way I think of so many technologies which can work with silverlight, not only because Silverlight can run on HTML or Silverlight can contact Webserivce, but because of it is making use of XAML.

Then I think of a Webserivce which return a string which is a string of XAML coding. It is so great to do so. Let say I have a SQL and after getting the data from the DataBase, maybe Information of Staffs. And I want to create a list of cards which includes the information of all staffs of my company. I can simply do that with all work on WebService but not Silverlight.

It has both advantages and disadvantages. For Adv, some class cannot be passed to Silverlight from Webservice (ArrayList, HashTable..) but we can manipulate all these into the form we want to show in XAML and pass that string. Yet, on the other hand, the xaml code will be so long that lengthens the time of downloading from the webserive.

By the way, Let me show an example here for the WebService.

using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Data;
using System.Data.SqlClient;
using System.Web.Script.Services;
using System.Text;
using System.Configuration;
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService]
public class MyService : System.Web.Services.WebServices
{
public MyService()
{
}
[WebMethod]
public string Get_StaffInfo(string id)
{
int nElement = 0;
StringBuilder strReturn = new StringBuilder();
strReturn.Append("");
SqlConnection sqlCon = null;
try
{
string strConnectionString = (string)ConfigurationManager.ConnectionStrings["StaffDataBase"].ConnectionStrings;
sqlCon = new SqlConnection(strConnectionString);
SqlCommand sqlCom = new SqlCommand();
sqlCom.Connection = sqlCon;
sqlCom.CommandType= CommandType.Text;
sqlCom.CommandText = "SELECT ScreenName From dbo.Staffs WHERE (StaffId = @strId)";
sqlCom.Parameters.Add(new SqlParameter("@strId", id));
sqlCon.Open();
SqlDataReader sRead = sqlCom.ExecuteReader();
while (sRead.Read())
{
strReturn.AppendFormat(" nElement += 20;
}
}
catch
{
strReturn = new StringBuilder();
strReturn.Append("");
}
finally
{
strReturn.Append("
" );
if (sqlCon != null) sqlCon.Close();
}
return strReturn.ToString();
}
}


Inside your Silverlight you call this

namespace SL2WebSrv
{
public partial class Page : UserControl
{
WebServiceProxy.ServiceSoapClient mydata = new SL2WebSrv.WebServiceProxy.ServiceSoapClient();
public Page()
{
InitializeComponent();
Loaded += new RoutedEventHandler(Page_Loaded);
}
void Page_Loaded(object sender, RoutedEventArgs e)
{
mydata.Get_StaffInfoAsync("1");
mydata.Get_StaffInfoCompleted += new EventHandler(mydata_Get_StaffInfoCompleted);
}
void mydata_Get_StaffInfoCompleted(object sender, SL2WebSrv.WebServiceProxy.Get_StaffInfoCompletedEventArgs e)
{
if (e.Error == null)
{
Canvas newStaff = XamlReader.Load(e.Result) as Canvas;
LayoutRoot.Children.Add(newStaff);
}
}
}
}


After all this tutorial, I hope more developers can know more about how powerful the Silverlight is and of course the XAML.

It can really work with so much thing.... not only Webservice but also JSP and AJAX and ASP.NET...

Live with Light
SteveWong (Hong Kong)

Tuesday, June 3, 2008

0
MIX2008HK

Wow! I have been waiting for many many days for this event.

As I know many different countries have held MIX2008 but not HongKong.

Details are as follow:






































Date:
July 11, 2008 (Friday)
Time:
2:30 - 4:30pm
(Registration: 2:00 – 2:30pm)
Venue:
Grand Ballroom, Lower Lobby, Conrad Hong Kong,
Pacific Place, 88 Queensway, Hong Kong
Language:
Cantonese
Admission:
FREE
Enquiry Hotline:
2388 9600

 Reference Web Link: http://www.microsoft.com/hk/msdn/mixessentials2008/

Join It NOW!

1
Animation and Storyboard

Before getting closer to Silverlight, I used to make animation and some application by Flash.

Now, I have to remind all the people, who used to design Flash Application before, should be clear that it has a new system in Silverlight which is totally different from Flash.

We have Storyboard to control the animation of different objects but we have Movie Clip to control those in Flash.

In flash we have to create animation by time line everywhere, but we can do all the animation separately in Silverlight.

We create animation in code-behind as follow:

First we create our new Storyboard and Double Animation :

[sourcecode language='csharp']Storyboard Reflection_Story1 = new Storyboard(); 
DoubleAnimation Reflection_fades = new DoubleAnimation();
[/sourcecode]

Then we have to set what the animation do, the value changed from .... to ....

[sourcecode language='csharp']Reflection_fades.From = 0;
Reflection_fades.To = 1;
[/sourcecode]

Furthermore, we have to let the computer know, how long is the animation last for?

[sourcecode language='csharp']Reflection_fades.Duration = new Duration(TimeSpan.Parse("0:0:1"));
[/sourcecode]

After that, what else we left? We have to tell the computer which object we want to apply for this animation.

[sourcecode language='csharp']Storyboard.SetTarget(Reflection_fades, Target_item);
[/sourcecode]

Also, the property that you are changing from 0 to 1 on the Targert_item.

[sourcecode language='csharp']Storyboard.SetTargetProperty(Reflection_fades, "(Target_item.Opacity)");
[/sourcecode]

Things left are quite simple and easy to understand!
We should let the Storyboard to control our animation, thus we add(hook) it onto the Storyboard.
Of course, we should then add the Storyboard into the Resources so that we can see it in the application.

[sourcecode language='csharp']Reflection_Story1.Children.Add(Reflection_fades);
LayoutRoot.Resources.Add(Reflection_Story1);
[/sourcecode]

Lastly, we should make it starts so we can see what happens to the Opacity of the item.

[sourcecode language='csharp']Reflection_Story1.Begin();
[/sourcecode]

Example is almost finished here, but for more details, you can refer to MSDN.

Because users also need to have a clear concepts of the use of different Animation (like Double, Point...)

Live With Light
Steve Wong (Hong Kong)

Sunday, June 1, 2008

0
Setting source of Images

This week end, I am so busy with my heavy work load... homework! But, I still want to share my experience on writeing Silverlight Application.

As I remembered, I have seen more than ten posts asking for the blinding of the source of their images.

Actually people want to make use of the images that they added to the project.

Honestly speaking, it has so many ways to do the trick.

First one:

[sourcecode language='csharp']Image Img = new Image();
BitmapImage bi3 = new BitmapImage();
bi3.UriSource = new Uri("pic.gif", UriKind.Relative);
Img.Source = bi3;
[/sourcecode]

Let me explain a little bit. If you added the image to your project, it is better for you to use UriKind.Relative. Just like the word "Relative" it is taking the resources relatively to the project. But how about somethings that are not added to the project?

[sourcecode language='csharp']Image Img = new Image();
BitmapImage bi3 = new BitmapImage();
bi3.UriSource = new Uri("http://localhost/pic.gif", UriKind.Absolute);
Img.Source = bi3;
[/sourcecode]



Apart from setting it programmatically with C#, you can also add it with xaml code throught C#.

[sourcecode language='csharp']Image img = XamlReader.Load("xmlns=\"http://schemas.microsoft.com/client/2007\"
xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\ " / > " ) as Image;
Layoutroot.children.add(img);
[/sourcecode]




It is rare to see people using XamlReader, but it can really do the trick!

Live with Light
Steve Wong (Hong Kong)

Saturday, May 31, 2008

0
Listbox

I've remembered one day, I am doing my Imagine Cup coding part in Silverlight.

Suddenly, List of check box, List of Radio Button , List of Pic with Description come across in my mind.

Then, I think of a good way to do so. After a moment, I have these ideas.

 

Let me briefly explain. I will use a stackpanel to store the items for each item in list. Then add the stackpanel into the list.

Let say we have a list of checkbox and a list of redio button.

It is easy for us to create the list like this.

[sourcecode language='csharp']
ListBox lb = new ListBox();
for (int i = 0; i <= 7; i++)
{
    CheckBox cb = new CheckBox(); 
    cb.Content = "Choice" + i.ToString();
    lb.Items.Add(cb);
    // Of course you can add some Event here for

[/sourcecode]

 

Case of Radio button  is the similar, so I dont explain so much here.

But for the case of Pic with Desc...

I will do like this.

[sourcecode language='csharp']
ListBox lb = new ListBox();
for (int i = 0; i <= 7; i++)
{
    Image Img = new Image();
    BitmapImage bi = new BitmapImage(); 
    string k = "pic" + i.ToString();
    TextBlock tb = new TextBlock();
    tb.Text = k;
    k += ".jpg";
    bi.UriSource = new Uri(k, UriKind.Relative);
    Img.Source = bi;
    StackPanel sp = new StackPanel();
    sp.Add(Img);
    sp.Add(tb);
    lb.Items.Add(sp);
}  
[/sourcecode]

Hope this can help more people to know more about Silverlight.

Live with Light!

Steve Wong (Hong Kong)

0
Xml and Linq in Silverlight

While answering a post in silverlight.net froum, I am surprised that the Silverlight work so well with XML WebService. 

First, in Xml WebService, you usually pass the Xml String to the Silverlight Application or using Http.Request to get the string by the Application itself. Silverlight can also parse it however you get it.

Now, I am going to introduce a good way to use the Linq with Silverlight.

Assume, you get a string by Xml Service after the Async Completed. That is,

[sourcecode language='xml']

    
        Steve
        17
        Student
        18-11-1990
    

    
        Hazel
        17
        Student
        14-12-1990
    

    ...
    ...
    ...

[/sourcecode]

 

And Suppose there is so many records here. It is very complicated for you to use XmlReader
Now, XDocument is introduced.

[sourcecode language='csharp']
string[,] mydata = new string[100,4]

if (e.Error == null)
{
    int i = -1;
    XDocument xd = XDocument.Parse(e.Result);
    var v = from g in xd.Descendants("UserRecords" )
select new 
            {
                uname = g.Element("Name").Value,
                uage = g.Element("Age").Value,
                uocc = g.Element("Occupation").Value,
                udob = g.Element("Birthday").Value,
            }; 
    foreach (var itm in v)
    {
        i++;
        mydata[i,0] = itm.uname.Trim();
        mydata[i,1] = itm.uage.Trim();
        mydata[i,2] = itm.uocc.Trim();
        mydata[i,3] = itm.udob.Trim();
    }

[/sourcecode]

Furthermore, if the data is not present in this way, is as follow,

[sourcecode language='xml']


Steve
17


Hazel
17


[/sourcecode]

The way in parsing this in similar.



[sourcecode language='csharp']
public class RankingList
{
public string name {get ; set; }
public string age {get ; set; }
}
if (e.Error == null)
{
            List list = new List();
            XDocument xd = XDocument.Parse(e.Result);
            var v = from row in xd.Descendants("Rank")
                    select row.Elements("FIELD").ToDictionary(r=>r.Attribute("name").Value, r=>r.Value);
            foreach (var itm in v)
            {
                    RankingList t = new RankingList();
                    t.name = itm["Name"];
                    t.age = itm["Age"];
                    list.Add(t);
            }
}
[/sourcecode]

 

I hope everyone can familiar with this Linq and Xml in Silverlight.


Live with Light.


Steve Wong (Hong Kong)


 

Friday, May 30, 2008

0
Navigation Bar

It seems that most people are very confused with designing a navigation for their own website
Let me introduce my own one.

First of all, we should have those thumbnail-sized  icons inside the bar. I suggest people download them from gallery in Microsoft.com. There is a tip on searching those icon. Please enter 'png" for the searching keyword.

After downloaded all of them, we should add them into a stackpanel in xaml file.
Let see here.


Then, we should add four storyboard for three case

  1. Mouse enter the region of one of the icons

  2. Mouse leave the region of one of the icons

  3. Mouse click on one of the region


[sourcecode language='xml']

      
      
      


      
      
      


      
      
      


      
      
      

[/sourcecode]

After that, we should try to finish the work with C#
We should have three case now as mentioned before.

[sourcecode language='csharp']
string CurrPage = null;
Image CurrImg = null;
int Curr = 0;
TextBlock e_msg = new TextBlock();
#region Navigation Animation Starts Here
void Navigation_MouseLeave(object sender, MouseEventArgs e)
{
    Image pic = sender as Image;
    if (pic != null)
    {
        if (CurrPage != pic.Name)
        {
            pic.SetValue(Canvas.ZIndexProperty, 1);
            foreach (Timeline tl in LeaveButtonSB.Children)
            {
                Storyboard.SetTarget(tl, pic);
            }
            LeaveButtonSB.Begin();
        }
        else
        {
            e_msg.Text = "It is clicked!";
        }
    }
}
void Navigation_MouseEnter(object sender, MouseEventArgs e)
{
    Image pic = sender as Image;
    if (pic != null)
    {
        if (CurrPage != pic.Name)
        {
            pic.SetValue(Canvas.ZIndexProperty, 10);
            foreach (Timeline tl in EnterButtonSB.Children)
            {
                Storyboard.SetTarget(tl, pic);
            }
            EnterButtonSB.Begin();
        }
        else
        {
            e_msg.Text = "It is clicked!";
        }
    }
        }
#endregion Navigation Animation Ends Here
#region PageShowing Starts Here
public void ShowPage(object sender, MouseButtonEventArgs e)
{
    Image pic = sender as Image;
    if (pic != null)
    {
        if (CurrPage != pic.Name && CurrImg != pic)
        {
            if (CurrImg != null)
            {
                GlowButtonSB.Stop();
                foreach (Timeline tl in ResetButtonSB.Children)
                {
                    Storyboard.SetTarget(tl, CurrImg);
                }
                ResetButtonSB.Begin();
            }
            foreach (Timeline tl in GlowButtonSB.Children)
            {
                Storyboard.SetTarget(tl, (sender as Image));
            }
            GlowButtonSB.Begin();
            CurrPage = pic.Name;
            CurrImg = pic;
            //Show Page doing here
        }
        else
        {
            e_msg.Text = "Pic is needed for the sender in ShowPage";
        }
    }
    else
    {
        e_msg.Text = "It is clicked!";
    }
}
[/sourcecode]

This time, I really control all the stuff in C# and Blend, never in ASP.NET.
Ofcoure, there is a way round in doing this trick by adding only a navigation bar in the MasterPage.
Just Like http://www.silverlight.net/
I hope everyone will love this navigation bar.

Thursday, May 29, 2008

0
Let's say "I LOVE YOU" to my dear computer

After the release of Siverlight 2.0, I do start reading the tutorials online. Of course, it is a very hard time for me becuase I am just a secondary school student. I spend most of the time at shcool on school day, leaving about 3 hours for me to read the posts at silverlight.net and sure I will answer them.

As I heard before, it is newly updated for Visual Studio to have a code behind on the Silverlight, I don't know if it is true but it is so powerful that the xaml and xaml.cs can work so well with each other.

I had my own computer when I was Primary four. Starting from that day, it should be a summer holiday, I had started to borrow books from the public library, all books are so call Deep Look in ASP, CGI and PHP, some maybe HTML and Flash. When I was Primary five, my primary school had a workshop for me to learn Flash. I remember that is Flash 4.0. Learning for a few days, I just fell in love with computer and I told myself that I must become a programmer.

Nowadays, I do not need to borrow books because online learning materials are available wherever in MSDN, silverlight.net or MVP's Blog.

I just want to be member of MVPs. It is a great honour to become a MVP. I do not only share my own experience of programming but also my experience of how do I work with computer. I know many programmers complain about the Async and Sync in cooperate webservice and silverlight. I do support the elimination of Sync. It is really protecting the platform ...
Starting from today, I will start writing my own blog here ... of course only about programming here.

10
About Steve

Steve Wong is a High School Student and a Silverlight, WPF, WCF, C# developer who has a passion for emerging technologies. He is an active answerer in Silverlight Community. He have learnt how to programme since he was 8. He tried developing different kind of applicaton including Flash, PHP, ASP. Recently, he has been awarded as Microsoft Most Valuable Professional(MVP) in the Client Applicatoin Devlopment(Client App Dev) categories.

Steve is now 18 years old and lives in Hong Kong with his family. You can contact him at watercubic@hotmail.com.



image

MVP (Client App Dev)