Welcome to MSDN Blogs Sign in | Join | Help

Internet Explorer 8 is shipped today

I just saw email from one of our company's VPs about IE8 is shipped today, and can be downloaded from here.
Posted by zainala | 1 Comments
Filed under:

Has Windows Vista issues? Use Microsoft Answers to find the solution

Look for the answers for your Windows Vista problems from Microsoft Answers site.
Posted by zainala | 1 Comments
Filed under:

Photosynth in Silverlight

This is very cool, check this out.
Posted by zainala | 0 Comments
Filed under: ,

Silverlight on Linux Beta is released

Soon we'll start seeing Silverlight application running on the Linux platform. More info on the project Moonlight and the plugin download can be found here

 

Posted by zainala | 0 Comments
Filed under:

Putting resource in separate xaml files

In Silverlight, we usually define several shared resources (i.e. definition of Color, Brush, Style, etc) in an individual xaml file (i.e. inside <UserControl.Resources></UserControl.Resources>, which scope is local to that file only) or in the App.xaml file (i.e. inside <Application.Resources></Application.Resources>, which scope is global to the app). The latter approach is good way to share resources but it can easily make the App.xaml file becomes huge. Another approach is to put the resources in one or more xaml files, which can be loaded at runtime.

For example, our app has a button control on the page, the xaml code looks something like:

<Button x:Name="MyButton" Content="My Sample Button" />

We want to assign one of the button properties with resource we load externally. Following are steps to create the separate xaml resource file and use the resources in the app:

  1. Create an empty xaml file (i.e. let's name it MyResources.xaml) and add it to the Silverlight project
  2. Change the Build Action property of the file from "None" or "Page" to "Content"
  3. Put the resource dictionary definition in the xaml file, for example:

<ResourceDictionary

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <SolidColorBrush x:Name="RedColorBrush"

                     Color="Red"

                     />

</ResourceDictionary>

Then add following code to load the resource dictionary and use the brush object on the existing button:

            // Read resources.xaml included in the project

            string xaml = null;

            StreamResourceInfo sri = Application.GetResourceStream(new Uri("MyResources.xaml", UriKind.Relative));

            using (StreamReader reader = new StreamReader(sri.Stream))

            {

                xaml = reader.ReadToEnd();

            }

 

            // Load the resource dictionary and access the resource using key

            if (xaml != null)

            {

                _globalResources = (ResourceDictionary)XamlReader.Load(xaml);

 

                // Now we can use the resource defined in the dictionary

                SolidColorBrush redColorBrush = (SolidColorBrush) _globalResources ["RedColorBrush"];

                MyButton.Background = redColorBrush;

            }

 

Posted by zainala | 3 Comments
Filed under: ,

Cool Silverlight debugging tool

This tool Silverlight Spy is pretty neat for seeing what inside Silverlight app.
Posted by zainala | 1 Comments
Filed under:

Get rid of file hiberfil.sys

I was working on my old machine running Windows XP to connect to internet (it hasn't connected to internet for years), and when installing Windows Update, the disk space on C:\ drive seems almost full. Then I noticed there's file called hiberfil.sys (used by Windows when hibernate is enabled) that consumes almost half GB. I tried deleting the file from Windows Explorer but got access denied error. Finally, by running "powercfg -h off" from Command window, the file was deleted automatically by Windows and I got plenty free space :-)
Posted by zainala | 1 Comments
Filed under:

Changing HTML page title from Silverlight

Recently I wrote following Silverlight code and got stuck with the runtime error (as being commented below).

            ScriptObjectCollection soc = HtmlPage.Document.GetElementsByTagName("Title");

            if (soc != null && soc.Count > 0)

            {

                HtmlElement titleElement = (HtmlElement)soc[0];

                string title = (string)titleElement.GetProperty("innerHTML");

                // the code below will give me runtime error

                titleElement.SetProperty("innerHTML", title + " :-)");

            } 

Basically the code logic is to get the reference to <TITLE> element, and then get the inner html text and set it with new value. I wonder why I could not set the innerHTML property of the element even though I could get the html page title using the same property. I posted my question to our Silverlight internal forum, and learned that the innerHTML property is read-only for <TITLE> element (and some other elements which is actually documented here), and the MSDN documentation also mentions that we can change the value of <TITLE> element by assigning document.title properly. Therefore, my code above needs to be changed to:

            ScriptObjectCollection soc = HtmlPage.Document.GetElementsByTagName("Title");

            if (soc != null && soc.Count > 0)

            {

                HtmlElement titleElement = (HtmlElement)soc[0];

                string title = (string)titleElement.GetProperty("innerHTML");

                HtmlPage.Document.SetProperty("title", title + " :-)");

            }

It works perfectly now (the page title changes). I hope this helps in case you run into the same problem.

Posted by zainala | 1 Comments
Filed under:

Generic delegate in C# 3.0 or .NET 3.5

As we do event-based programming or implement publish-subscribe pattern, we use the delegate feature from .NET heavily. The sample code below demonstrates simple usage of the feature.

    public delegate void DataChangedDelegate(int oldValue, int newValue);

 

    class Foo

    {

        public DataChangedDelegate OnDataChanged = null;

 

        private int _data = 0;

 

        public int Data

        {

            get { return _data; }

            set { UpdateData(value); }

        }

 

        private void UpdateData(int updatedData)

        {

            if (OnDataChanged != null)

            {

                OnDataChanged(_data, updatedData);

            }

            _data = updatedData;

        }

    }

We can then create an instance of Foo class, and hook up the event handler to its public delegate as shown below.

     class Program

    {

        static void Main(string[] args)

        {

            Foo foo = new Foo();

            foo.OnDataChanged += OnDataChanged;

            foo.Data = 2;

            Console.WriteLine();

        }

 

        static void OnDataChanged(int oldValue, int newValue)

        {

            Console.WriteLine("Data changes from " + oldValue + " to " + newValue);

        }

    }

 

C# 3.0 or .NET 3.5 has new feature that provides us a set of generic delegates with the name "Action" or "Func", the difference between them is Action does not have return type (void), while Func has return type (refer to MSDN documentation). So from example above we can remove following code:

    public delegate void DataChangedDelegate(int oldValue, int newValue);

and replace following code: 

        public DataChangedDelegate OnDataChanged = null;

with:

        public Action<int, int> OnDataChanged = null; 

If the delegate returns bool data type for example, then we can use Func function such as:

        public Func<int, int, bool> OnDataChanged = null;

 

Although this new feature allows us not to declare the delegate types (means less line of code), but we may use our judgement whether to use it or not. The reason is because sometimes we may prefer to name the delegate type to make us better understand the code. Another thing is we can't use the delegate type we created interchangeably with its counterpart generic delegates unfortunately even though they have same signature (and not with explicit conversion either). For example, the following code below will not work.

            DataChangedDelegate dataChanged;

            Action<int, int> genericFunc;

            dataChanged = genericFunc;      // compile error 

 

Posted by zainala | 3 Comments

Innovation, Failure and Success

I just read this pretty good book The Riddle: Where Ideas Come From and How to Have Better Ones, and at the last chapter it suggests us to discuss these three important words to help us find our conceptual creativity.

Innovation: Don't innovate, but solve problems instead. By focusing on problem solving rather than creation of unique things, we will increase our odds of success in the pursuit of innovation. Become a problem solver, and not an innovator!

Failure: When things go wrong (as they will, or we didn't try hard enough), stop and ask why. Later when things go right (as they will), also ask where did the idea come from? What were we doing prior to having the big idea? Keep track of why and what led to these ideas, write them down and study this information trail. We will begin to observe a pattern beyond the happy accident.

Success: Although failure reduces the number of possible solutions, success ends the search for a solution, and ironically once the journey ends, curiosity is often shelved as the new idea moves into the generally accepted category of great ideas. Success begets a new set of rules that blinds us to new opportunities. Sustainable success is not a destination, but it is an aspiration (think it more as a process than a place).

 

Posted by zainala | 1 Comments
Filed under:

Incorrect installed date in Windows Update

My laptop informed me about new windows update, which then I installed it. After the installation was done, I was curious what's the update. I viewed the update history and surprised to find that the update's date installed is 1/22/2081 instead of today's date (see picture below). This is weird and it seems like a bug in Windows Update.

Windows Update weirdness

Posted by zainala | 1 Comments
Filed under:

Silverlight Toolkit November 2008 is released

The Silverlight Toolkit is a collection of Silverlight controls, components and utilities made available outside the normal Silverlight release cycle (Silverlight 2 was released about two weeks ago). The binaries, source code, documentation and samples can be downloaded from here.

Posted by zainala | 1 Comments
Filed under:

Professional Developers Conference 2008

This week Microsoft will host a big event in LA, check here.
Posted by zainala | 0 Comments
Filed under: ,

Model View Controller in ASP.NET

Today I just learned ASP.NET enables us to build Model View Controller (MVC) applications. I need to explore further later, and this ASP.NET site has some useful information about it. The Microsoft ASP.NET MVC Beta was released last week and can be downloaded from here.
Posted by zainala | 0 Comments
Filed under: ,

Microsoft releases Silverlight 2

The official news can be read here, but the runtime will be available for download on Tuesday, Oct 14th 2008 at this official Silverlight site. Kudo to the Silverlight folks!
Posted by zainala | 0 Comments
Filed under: ,
More Posts Next page »
 
Page view tracker