2010年10月20日

Design-Time Attributes for Components and Behaviors

使用 Expression Blend 設計 Silverlight 介面時,若希望設計人員能更清楚 Property 的含意,可以透過 Design-Time Attributes 來協助。

以下列出可能會使用到的項目:


可以在 class 上加入 Description, 來說明物件的功用 (上圖)
    [Description("可點選物件 - 可以設定為正確或錯誤點選")]
    public class ClickItemProcess : QuestionGroupBase<panel>
    {
       //..
    }


Description 也可以使用在 property 上, 並能以 Category 來分類 (上圖)
        [Category("遊戲功能"), Description("若此物件為錯誤答案,點選後所顯示的動畫(Storyboard)")]
        public string WrongAnswerAnimation
        {
            get { return (string)GetValue(WrongAnswerAnimationProperty); }
            set { SetValue(WrongAnswerAnimationProperty, value); }
        }

如果 property 不希望出現在 Expression Blend 的面板上, 可以將 Browsable 設為 false
        Result m_Result = Result.NoAnswer;
         [Browsable(false)]
        public Result Result
        {
            get { return m_Result; }
            set { m_Result = value; }
        }


如果 properties 屬於 state, element 或 storyboard, 並希望直接出現下拉選單,則可以用 CustomPropertyValueEditorAttribute 來設定。CustomPropertyValueEditor.StateName, CustomPropertyValueEditor.Element, CustomPropertyValueEditor.Storyboard 分別對應這三種不同類型的物件。

        [CustomPropertyValueEditorAttribute(CustomPropertyValueEditor.Storyboard)] 
        public Storyboard RightAnswerAnimation
        {
            get { return (Storyboard)GetValue(RightAnswerAnimationProperty); }
            set { SetValue(RightAnswerAnimationProperty, value); }
        }

另外,對於 TriggerAction, 可以利用 DefaultTriggerAttribute 預設 event。以及利用 TypeConstraintAttribute 來限制 TargetedTriggerAction 與 EventTriggerBase 的 AssociatedObject 型態。

    [DefaultTrigger(typeof(UIElement), typeof(EventTrigger), "MouseLeftButtonDown")]
    [DefaultTrigger(typeof(ButtonBase), typeof(EventTrigger), "Click")]
    public class WaveAction : TriggerAction<UIElement> { }

[reference]
MSDN: Design-Time Attributes for Components
State, Element, and Storyboard Pickers
Silverlight Hover Behavior

2010年10月12日

Free Silverlight Hosting

在部落格上探討 Silverlight 的技術與應用,如果不能顯示範例執行的樣貌,是一件令人苦惱的事情。當然,可以花錢用虛擬主機解決,只是還沒有收到 Google AdSense 的支票,卻要先支出,也太吃虧了。

先前微軟提供了 Microsoft Silverlight Streaming by Windows Live 免費的 hosting 服務,2010 已由 Azure 取代,也有 Introductory Special 免費方案 (Limited Amount at No Charge),但是台灣地區卻遲遲未上線。想亂編一個美國的地址去註冊,因為要輸入信用卡號,覺得不妥而作罷。

好在發現可以利用 Google App Engine application 來解決,雖然要多繞一圈,但還算值得,而且第二個 ap 之後,也會方便許多。步驟如下:

  1. 建立 Python 開發環境,並安裝 Google App Engine 上傳檔案的工具
  2. 利用 Google App Engine 建立帳號並新增 Application
  3. 撰寫 app.yaml 來設定上傳的檔案,而 .py (以 Python為例) 可以是一個空檔案
  4. 利用 appcfg.py 上傳 app.yaml, silverlight.js, .xap 至 Server
  5. 在部落格的網頁中,加入呼叫 .xap 的語法

app.yaml 範例:

application: dysonliu
version: 1
runtime: python
api_version: 1

handlers:

- url: /Silverlight3D.xap
static_files: Silverlight3D.xap
upload: Silverlight3D.xap
mime_type: application/x-silverlight-app

- url: /Silverlight.js
static_files: Silverlight.js
upload: Silverlight.js

- url: .*
script: Silverlight3D.py


插入部落格 HTML 的語法,可以由 Silverlight 的專案抄過來,然後把 Silverlight.js 與 .xap 的位置改掉,並加入寬度與高度的設定。

[reference]
Google 應用服務引擎 - 入門指南
How to embed a silverlight control on a Google Sites webpage?

Deploying Vue & .NET with Google OAuth on GCP Cloud Run

Deploying Vue & .NET with Google OAuth on GCP Cloud Run Deploying Vue & .NET with Google OAuth on GCP Cloud Run...