blend

เมื่อคราว Silverlight 1 ออกมา เราก็ใช้ภาษาไทยกับ Silverlight ได้แบบพอถูไถกันไป พอคราว Silverlight 2 Beta 2 ออกมา ทาง GreatFriends ก็ได้แสดงวิธีการใช้งานภาษาไทยใน Silverligh 2 Beta 2 ไปแล้ว คราวนี้เมื่อตัวจริงออกมาเราก็จะมาดูว่าภาษาไทยได้รับการปรับปรุงไปขนาดไหนแล้ว โดยในครั้งนี้เราจะใช้แค่เพียง Expression Blend 2 Service Pack 1 เท่านั้น ถ้ายังไม่มีสามารถดาวน์โหลดได้ที่ http://silverlight.net/GetStarted/

หลังจากเปิด Blend ขึ้นมาแล้วก็ลองสร้างโปรเจคใหม่ชื่อ ThaiLang

createproject

สร้าง TextBox และ TextBlock ขึ้นมาอย่างละอัน ใครขี้เกียจจะใช้ XAML ข้างล่าง

<Grid x:Name="LayoutRoot" Background="#FFBDBDBD">
    <Grid.RowDefinitions>
        <RowDefinition/>
        <RowDefinition/>
    </Grid.RowDefinitions>
    <TextBlock Text="TextBlock" TextWrapping="Wrap" Margin="50,10,50,10" Grid.Row="0"/>
    <TextBox HorizontalAlignment="Stretch" Margin="50,10,50,10" Width="Auto" Grid.Row="1" Text="TextBox" TextWrapping="Wrap"/>
</Grid>
2-textblock-textbox

ทีนี้ถ้าเราลองใส่ข้อความภาษาไทยลงไป

๏ เป็นมนุษย์สุดประเสริฐเลิศคุณค่า
กว่าบรรดาฝูงสัตว์เดรัจฉาน
จงฟันฝ่าพัฒนาวิชาการ
อย่าล้างผลาญฤๅเข่นฆ่าบีฑาใคร
ไม่ถือโทษโกรธแช่งซัดฮึดฮัดด่า
หัดอภัยเหมือนกีฬาอัชฌาสัย
ปฏิบัติประพฤติกฎกําหนดใจ
พูดจาให้จ๊ะๆ จ๋าๆ น่าฟั งเอยฯ

พ่อปู่พี่ปี่ฎฐุญุกิสมิํธมฺมํเกื็อกป่า

๐๑๒๓๔๕๖๗๘๙ กกๆ ๚ะ๛
A QUICK BROWN FOX JUMPS OVER THE LAZY DOG.
a quick brown fox jumps over the lazy dog.
0123456789

เละครับเละ

thai-fail

เพราะว่าฟอนท์ตั้งต้นที่ติดมากับ Silverlight ที่ชื่อ Portable User Interface ไม่สามารถแสดงภาษาไทยได้ก็เลยกลายเป็นสี่เหลี่ยมๆไปหมด แต่ถ้าฟอนท์แสดงภาษาไทยได้ก็สบายเรา

งั้นก็ลองปรับให้ใช้ฟอนท์ที่รองรับภาษาไทยอย่าง Tahoma ดูซิ

font1

เป็นภาษาไทยแล้วล่ะ แต่ Blend จะขึ้นข้อความมาเตือนอะไรบางอย่าง

The font, Tahoma, isn’t a built-in silverlight font. You must embed this font for it to display on your Silverlight Application

เมื่อเราติ๊กคำว่า Embed ในแท็บ Properties แล้วข้อความเมื่อกี้ก็หายไป

font2

แต่เราจะได้สิ่งนี้มาแทน

file-explorer

ถ้าเราขยับๆ จะเห็น Silverlight 2.0 รองรับการตัดคำภาษาไทยแล้ว เย่

result

แต่ก็มาตกม้าตายตอนท้ายเพราะว่าพอลองใช้ TextBox ว่าพอกดปุ่มสระปุ๊บก็เละครับ Silverlight Object หายไปเลย ทางแก้ง่ายมาก ก็อย่าเพิ่งใช้ Silverlight กับงานที่ต้องกรอกข้อมูลหรือไม่ก็ใช้วิธีเดียวกับ Silverlight 1.0 คือเอา HTML input textbox มาใช้แทน แล้วก็อย่าลืมเข้าไปดูที่บักนี้ แล้วเพิ่มลง watchlist ด้วย เค้าจะได้รู้ว่าเรารอให้เค้าแก้บักนี้กันหลายคนเหมือนกัน

Blend to ASPX

18 Apr 2008

ให้ตายสิไมโครซอฟท์ ออก Microsoft Expression Blend มาให้ใช้ แต่กลับไม่มีวิธีง่ายๆในการฝังไฟล์ Silverlight ลงใน ASP.NET !!!

เรื่องเริ่มต้นที่ว่าตอนหัดใช้ Silverlight ก็ต้องมานั่งแกะเองทีละขั้น ตอนนั้นก็คิดว่า ของใหม่เครื่องมือยังห่วยอยู่ ใช้งานยาก ก็น่าให้อภัย แต่ก็คิดว่า ซักวันมันต้องมีคนมาถามแน่ๆเลยว่าจะเอา XAML ไปใช้ยังไง

วันนี้เพื่อนมาถาม

นาย ม. says:
วีน ถามหน่อย สมมุติทำของใน blend เส็ดแล้ว จะใส่เข้าไปใน aspx ยังไง

โอ้…พระเจ้า ไมโครซอฟท์ทำสิ่งที่เราฝันไว้ได้จริงๆด้วย

Continue reading...

Recently, I have involved in a small silverlight project. As the rest of team has no experience with Silverlight but have played with WPF for a while, I suggest them to use shiny new Expression 2.5 with Silverlight 2.0 runtime at first. Unfortunately, using beta software is unbearable by the project owner aka client. Therefore we fall backed to the released Silverlight 1.0 runtime.

The development was progressed smoothly and all bugs we had found was fixed. With the help of Expression 2.5, the development was easier than earlier version. However, when the user acceptance testing had begun, a very serious bug was introduced in some user machines. No one in development team had seen this bug before . The only error message I had at that time was

ParserError- Unknown attribute Ignorable on element Canvas.
File: LoadingPage.xaml, line 8 character 3

This bug is obviously related to XAML parsing. So I fired up notepad and went to the problem line. Then I realized the attribute was added by Expression Blend 2.5. But I didn’t sure enough to conclude this was the cause as we, the development team, could run it perfectly both in development machines and my computer at home.

In order to reproduce the bug, I decided to uninstall my Silverlight runtime from the computer and found out the root of problem. Silverlight 1.0 and 1.1 runtime do not handle XAML file as a normal XML file. They parse XAML file as XAML file. If you introduce any new namespace to the file, parser will struck and you will got parser error. Though you can use Expression Blend to create and design Silverlight 1.0, the XAML code still cannot be utilized by Silverlight 1.0 runtime. Furthermore, if I correct understand, Silverlight 2.0 javascript API has been changed and Rectangle has the actualWidth attribute as TextBlock element. Because my javascript also caused an error after I fixed the XAML namespace bug.

Since this new namespace was introduced by Expression Blend 2.5 Preview, this can be concluded that Expression Blend 2.5 Preview is not fully backward compatible with Silverlight 1.0. Although in the system requirement page states Silverlight 2.0 beta 1 is required, I think it is for development machine and should not require the 2.0 runtime to be installed in the client box. As this version is just preview, I don’t think this bug is Microsoft fault. I blog this for everyone who wanna try the software to be concern.

PS. This issue has been reported to Microsoft.