SilverLight

リソースファイルに写真ファイルの利用

 リソースファイルに写真を追加すると、自動的に生成されたソースコードに、「System.Drawing.Bitmap」への参照がありますので、SilverLightでは利用できません。

 回避策として、予め写真ファイルの拡張子を削除して、Visual Studio のリソース追加画面で、リソースのタイプを「その他」を選択して、写真ファイルを追加します。ファイルを追加したら、自動的に生成されたソースコードでは、「byte[]」タイプとなります、これで、MemoryStreamで利用可能となります。    ソースコード例、UIにImageコントロールを追加します。

MemoryStream ms =new MemoryStream (SilverlightBusinessApplication1.Assets.Resources.Images.);
Image image = new Image();
BitmapImage bi = new BitmapImage();
bi.SetSource(ms);
image.Source = bi;

※作成した写真はPNGフォーマットに保存する必要があります。
#すべての画像フォーマットを試していませんが、BMPにする場合、BitmapImageのSetSourceメソッドが呼び出された時、下記のようなわけわからない例外が発生します。

Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED)

コントロールのAutoサイズ

XAMLで設定する場合

<button Height="Auto" ... />

ソースコードで設定する場合:

MyComponent.Width = double.NaN;

IsHitTestVisibleプロパティ

 透過処理した画像などの下のレイヤにボタンなどを置いた場合、透過処理した画像が邪魔してボタンをク&リックしたりできません。このときは、IsHitTestVisibleを使うとそのオブジェクトはマウスイベントを無視するようになります。

ビジュアル層でのヒット テスト http://msdn.microsoft.com/ja-jp/library/ms752097(v=vs.80).aspx

コントロールのライフサイクル

http://blogs.msdn.com/b/devdave/archive/2008/10/11/control-lifecycle.aspx

OnNavigatedTo Loaded event

Typically, you use the OnNavigatedTo method instead of creating an event handler for the Loaded event. The OnNavigatedTo method is preferable because it is only called once for each time the page becomes active. The Silverlight framework raises the Loaded event each time the element is added to the visual tree, which potentially can happen more than once when activating a page.

The OnNavigatedTo method is called for each request, even when the page is retrieved from the cache. You should include in this method code that must be executed for each request rather than placing that code in the Page constructor.

ダブルクリック

 Silvelightではデフォルトにダブルクリックのイベントが提供していません。ダブりクリックの動作を実装する必要があります、以下は実装のサンプルです。

 //クリックのポイント
 Point clickPosition_;
 
 //最後クリック時間
 public DateTime lastClick_ = DateTime.Now; 
 
 //最初クリック時間
 private bool firstClickDone_ = false;
 
 //マウス左ボタンダウン
 private void listBoxFileList_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
 {
    e.Handled = true;
 }
 
 //マウス左ボタンアップ
 private void listBoxFileList_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
 {
    if (e.Handled)
        return;
 
    UIElement element = sender as UIElement;
    DateTime clickTime = DateTime.Now;
 
    TimeSpan span = clickTime - lastClick_;
 
    // ダブルクリックの時間間隔は400ミリ秒とする
    if (span.TotalMilliseconds > 400 || firstClickDone_ == false)
    {
        clickPosition_ = e.GetPosition(element);
        firstClickDone_ = true;
        lastClick_ = DateTime.Now;
    }
    else
    {
        Point position = e.GetPosition(element);
        //ダブルクリックする時、マウスが移動しないこと
        if (Math.Abs(clickPosition_.X - position.X) < 4 && Math.Abs(clickPosition_.Y - position.Y) < 4) 
        {
            //この場合ダブルクリックと判定する
        }
        firstClickDone_ = false;
    }
 
    e.Handled = true;
 }

Labelコントロール

「Button」コントロールと同じく、「Content」プロパティに子コントロールを設定できます。



フレッツ光が月額556円~【GMOとくとくBB】

コメント:



(画像の文字列を入力して下さい)

トップ   編集 凍結 差分 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2019/12/02 (月) 12:47:33 (1628d)

yVoC[UNLIMITȂ1~] ECirŃ|C Yahoo yV LINEf[^[Ōz500~`I


z[y[W ̃NWbgJ[h COiq 萔O~ył񂫁z COsیI COze