之前一直做WPF現在開始接觸Slilverlight感觸很多。
今天做一個Button要求
有兩個圖片,button默認有一個圖片,鼠標over時用另一個圖片,
用wpf做的時候寫一個template很簡單,但silverlight和wpf寫起來不一樣
記錄一下。大概思路是兩個image鼠標MouseOver的時候一個Visible一個Collapsed
寫的是一個自定義控件,代碼和皮膚分離,很簡單的一個demo
代碼下載:ImageButtonTest.rar
先寫一個繼承自button的imagebutton類
代碼如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
namespace ImageButtonTest
{
/// <summary>
/// build by lp
/// </summary>
public class MyImageButton : Button
{
public static readonly DependencyProperty ImageNormalProperty =
DependencyProperty.Register("ImageNormal",
typeof(ImageSource),
typeof(MyImageButton),
new PropertyMetadata(null));
public static readonly DependencyProperty ImageHoverProperty =
DependencyProperty.Register("ImageHover",
typeof(ImageSource),
typeof(MyImageButton),
new PropertyMetadata(null));
新聞熱點
疑難解答
圖片精選