Nat Luengnaruemitchai

Geek Blog

  Home  |   Contact  |   Syndication    |   Login
  93 Posts | 0 Stories | 133 Comments | 243 Trackbacks

News

Archives

Post Categories

Blogroll

Wednesday, October 22, 2008 #

Some people may experience a problem with Java applet in Mozilla Firefox 3.0. For me, I noticed that after upgrading from Firefox 2.0 to Firefox 3.0, some of my applets don't work anymore. This happens when I have network.cookie.cookieBehavior setting = 1. This will disallow access to 3rd party cookies. However, it also has a side effect where it disallow cookie from the same site when fetching for Java applet codebase as well. Changing it back to 0 (Allow all cookies" fixes it.

http://kb.mozillazine.org/Network.cookie.cookieBehavior


Thursday, September 20, 2007 #

Yesterday, I had a problem where I need to hook up an event to a certain data condition. I first thought about EventTrigger. However, it does the other way around. This class is responsible for convert event into trigger. So I digged around WPF architecture to see what I can do and bingo. I found that I can create an attached property with the following construct

 

 

 

 

and then in XAML, you can register for this event by

<

 

TextBox Text="Try me">
    <
TextBox.Style>
        <Style TargetType="{x:Type TextBox}">
            <
Style.Triggers>
                <
Trigger Property="Text" Value="Cool">
                    <
Setter Property="me:Window1.SomethingHappened" Value="True" />
                </
Trigger>
            </
Style.Triggers>
        </
Style>
    </
TextBox.Style>
</
TextBox>
public static readonly DependencyProperty SomethingHappenedProperty = DependencyProperty.RegisterAttached("SomethingHappened",typeof(bool),typeof(Window1),new PropertyMetadata(false,new PropertyChangedCallback(SomethingHappened)));public bool GetSomethingHappened(DependencyObject d)
{
    return (bool)d.GetValue(SomethingHappenedProperty);
}
public void SetSomethingHappened(DependencyObject d, bool value)
{
    d.SetValue(SomethingHappenedProperty, value);
}
private void SomethingHappened(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
    // do something here
}

Tuesday, September 18, 2007 #

Andrew Flick announced that Infragistics WPF Express Edition will be free as well. Before this release, xamDataGrid suffered a lot of performance problem. It seems that they have fixed various performance problem. So I think I will give it a try again later. To try it out visit http://blogs.infragistics.com/blogs/andrew_flick/archive/2007/09/13/infragistics-netadvantage-for-wpf-express-aka-free-grid.aspx for more information.

Sunday, September 16, 2007 #

In Windows Forms application, we can use Control.IsInDesignMode or LicenseManager.UsageMode == LicenseUsageMode.Designtime to check whether your code is executing in DesignMode or not. You might wonder how would you do the same in WPF. Fortunately, Cider and Blend offers a similar functionality. You can test the following condition DesignerProperties.GetIsInDesignMode(new DependencyObject()).

ClickOnce deployment has problem with Proxy that requires authentication. You might get the following error:

(407) Proxy Authentication Required

If so, you would need to get a hotfix at http://support.microsoft.com/kb/917952/en-us.

For more detail, you can check out at http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=294738&SiteID=1


If you try to run any XBAP application on the machine that has ISS Proventia Buffer Overflow Protection (vpatch.exe) installed, you might experience COMException with HRESULT 0xFFFFFFFF. The workaround is to stop vpatch.exe. I hope Microsoft and ISS work together to fix this issue.

 


If you experience bad handle leaks in svchost.exe process like I did, what happened was a bug in a dll that leaks handles when you have some antivirus software installed. It might worth to get a hotfix from Microsoft. It is detailed at KB892489.

Tuesday, August 07, 2007 #

Sometimes, you would like to get a combobox where a user can type. This can be done by turning on IsEditable property to true. However, it opens another can of worm, it means the user can type anything in the combobox even text that is not in the ItemsSource.

To provide LimitToList feature, you can hook up an event to PreviewLostKeyboardFocus as follows:

 

        private void ComboBox_PreviewLostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)

        {

            if (!e.Handled)

            {

                TextBox textBox = e.OldFocus as TextBox;

                ComboBox comboBox = sender as ComboBox;

                if (textBox != null && comboBox!=null)

                {

                    DependencyObject common = comboBox.FindCommonVisualAncestor(e.NewFocus as DependencyObject);

                    // validate only the case when user step out of this control

                    if (common != comboBox)

                    {

                        bool invalid = !string.IsNullOrEmpty(textBox.Text) && comboBox.SelectedIndex < 0;

                        if (invalid)

                        {

                            e.Handled = true;

                        }

                    }

                }

            }

        }

Later, I will show you how to create a visual clue to indicate that the combobox is invalid


Sunday, July 29, 2007 #

I posted in MSDN Forum a while ago that I ran into a WPF bug that occurs when you put one template inside another template like

    <ListBox HorizontalContentAlignment="Stretch" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
        Background="Honeydew" ItemsSource="{Binding}">
        <ListBox.ItemTemplate>
                <DataTemplate>
   <ListBox ItemsSource="{Binding}">
    <ListBox.ItemTemplate>
     <DataTemplate>
      <etc..............
     </DataTemplate>
    </ListBox.ItemTemplate>
   </ListBox>
  </DataTemplate>
 </ListBox.ItemTemplate>
    </ListBox>

The above code won't fail during the compilation. However,during the run, you will notice that only the first item of the outer listbox will show up but not the rest. Sam Bent, WPF/WinFX Dev Lead answered that this is a nested template bug. If template is used nestedly, the result will be unexpected. To workaround, the template should be defined as a separated template in Resources section like:

<Window.Resources>
    <DataTemplate x:Key="InnerTemplate">
        <StackPanel>
            <ComboBox ItemsSource="{Binding Source={StaticResource CategoryData}, XPath=Category}"
            SelectedValue="{Binding XPath=Category}"/>
            <TextBlock Text="{Binding XPath=Title}" />
            <TextBlock Text="{Binding XPath=Summary}" />
        </StackPanel>
    </DataTemplate>
    <DataTemplate x:Key="OuterTemplate">
        <StackPanel>
            <ListBox HorizontalContentAlignment="Stretch" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
                ItemTemplate="{StaticResource InnerTemplate}" Background="Honeydew" ItemsSource="{Binding XPath=.}">
            </ListBox>
        </StackPanel>
    </DataTemplate>
</Window.Resources> 

<Grid VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
    <ListBox HorizontalContentAlignment="Stretch" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
            ItemTemplate="{StaticResource OuterTemplate}" Background="Honeydew">
        <ListBox.ItemsSource>
            <Binding Source="{StaticResource InventoryData}"
                    XPath="*[@Stock='out'] | *[@Number>=8 or @Number=3]"/>
        </ListBox.ItemsSource>
    </ListBox>
</Grid>

 


Sunday, February 11, 2007 #

As Bush's goverument proposed the extension of daylight saving time period, the daylight saving time will start in March and end in November in 2007 instead of April and October previously. This will cause a problem for unpatched system not to display time correctly. Therefore, several vendors have provided a patch for their own system including Microsoft. Microsoft released a KB928388 patch. What this patch does is to modify some registry keys that keep information about time offset and daylight saving information. This information is quite static. It stores time offset, the start of DST (Xth day of week of Yth month as well as the time difference between daylight saving time and regular time). For example, this information has been patched to Second Sunday in March at 02:00:00 and First Sunday in November at 02:00:00 respectively.

It looks OK right. System has been patched. Life is good. Not so fast, my friends. The operating system before Vista era doesn't really support Dynamic DST (Ability to keep different daylight saving information for different periods.) This means the time will be changed retroactively. For example,

Before the patch

TimeZone.CurrentTimeZone.GetUtcOffset(new DateTime(2006, 11, 1)) should return -05:00:00
TimeZone.CurrentTimeZone.GetUtcOffset(new DateTime(2007, 11, 1)) should return -05:00:00

After the patch

TimeZone.CurrentTimeZone.GetUtcOffset(new DateTime(2006, 11, 1)) should return -04:00:00
TimeZone.CurrentTimeZone.GetUtcOffset(new DateTime(2007, 11, 1)) should return -04:00:00

Expected behavior

TimeZone.CurrentTimeZone.GetUtcOffset(new DateTime(2006, 11, 1)) should return -05:00:00
TimeZone.CurrentTimeZone.GetUtcOffset(new DateTime(2007, 11, 1)) should return -04:00:00

First when I heard about this problem, I couldn't believe my own ears that Microsoft would provide a patch where it will cause a problem somewhere else but it is. The implication of this means if you store the data in UTC timezone to represent datetime, you stored 2006-11-1 12:00:00AM as 2006-11-1 05:00:00 AM previously and when you retrieve it back based on new patch, you will get 2006-11-1 01:00:00AM back instead. So if you search such date in the database probably you won't get anything back. The same problem applied with a case I found recently. We have a system that needs interopability between Java and .NET. We use the native implementation of Date where the DateTime in .NET will be converted into .NET ticks at UTC time sending over to Java side and then Java will convert .NET tick back to milliseconds since epoch and construct java.util.Date object in Java. Everything had been good until recently our beloved administrators installed timezone patch in every machine. One user started complain that she entered 2007-11-1 in the application but it turns out to get data on 2007-10-31 for her instead. What happened was 2007-11-1 in .NET Datetime will be converted into 2007-10-31 11:00PM and it got serialized into XML as 2007-10-31. When the data got transferred to the other side, it will return wrong data back to us. To make the story funnier, although Microsoft provided an API to get dynamic DST in Vista, .NET code seems to use the old function. Therefore it will return wrong timezone information as well. What a compatibility!

If you have a problem like me, I hope that the information provided here would help you not to spend too much time diagnose what's going on here.

Thanks Citrin Wayne for providing such responsive help, extensive information, and the great product.

Reference:
DYNAMIC_TIME_ZONE_INFORMATION
2007 time zone update for Microsoft Windows operating systems
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1180416&SiteID=1
More about JNBridgePro and the new daylight savings time rules


Wednesday, January 10, 2007 #

Bryant and Chris reported this issue a while ago. Now Microsoft just acknowledged the problem and put in a knowledge base article about this problem as KB911895. Hopefully Microsoft will release a resolution to this problem for Microsoft Vista Home Premium.

Monday, January 15, 2007 #

If you try to execute 32-bit version of mstsc.exe in Vista 64-bit by passing a .rdp file as an argument, it will act as if you do not pass any argument. I experience this a lot since I use IE 32-bit to open .rdp files on the web which will redirect to 32-bit version of mstsc.exe. Nelly kindly answered me that it will be fixed in Vista SP1. I don't know how long I have to wait given that RTM version hasn't been available to retail yet.

Tuesday, October 24, 2006 #

Many times, people use Uri.ToString() to convert Uri back into String. However, based on the documentation, ToString() actually returns the canonical string representation of the actual URL. This means the special characters that were previously escaped will be unescaped. If you try to use a string that returns from the function, it will be ok in most case except when you have escaped characters in there such as "%20" (" "), "%2b" ("+"), "%25 ("%"), etc. To make the code works right, you should actually use Uri.AbsoluteUri to return back the right representation of the URL itself. I found that WebBrowser.Url actually uses Uri.ToString() which prohibits users to pass in escaped characters as parts of URL. I hope that one day, it will be fixed.... hopefully in .NET 3.0?

Thursday, June 29, 2006 #

I'm an Intelli-J IDEA fan, but I will give it a try when Eclipse 3.2 is out tomorrow. http://www.eclipse.org/org/press-release/20060626callisto.php

Saturday, June 03, 2006 #

I just watched 2 guys mixing coke and mentos together to create some sorts of geysor. Pretty cool. (via Digg)

http://eepybird.com/dcm1.html