WPF封裝簡單的ImageButton控制項

2021-09-28 17:58:05 字數 1342 閱讀 3819

1、imagebutton自定義控制項類

public class ucimagebutton : button

#region properties

public static dependencyproperty normalimageproperty = dependencyproperty.register("normalimage", typeof(imagesource), typeof(ucimagebutton), new propertymetadata(null));

public imagesource normalimage

set

}public static readonly dependencyproperty hoverimageproperty = dependencyproperty.register("hoverimage", typeof(imagesource), typeof(ucimagebutton), new propertymetadata(null));

public imagesource hoverimage

set

}public static dependencyproperty pressedimageproperty = dependencyproperty.register("pressedimage", typeof(imagesource), typeof(ucimagebutton), new propertymetadata(null));

public imagesource pressedimage

set

}public static readonly dependencyproperty disabledimageproperty = dependencyproperty.register("disabledimage", typeof(imagesource), typeof(ucimagebutton), new propertymetadata(null));

public imagesource disabledimage

set

}#endregion

}

2、imagebutton的style樣式

注意triggers裡bind的寫法,

寫成:則找不到一直閃爍;

寫成:則會報錯;

需要寫成:

3、xaml用法

這裡有個問題,封裝的屬性還不完善,在使用時需要指定hoverimage、pressedimage的路徑,否則會發生閃爍,暫時還沒有找到好的解決方法,有解決方案的還請多多指教~

WPF簡單總結

wpf總結 xaml語言解析處理相關的程式集,是語言層面上的東西。使用這些命名空間中型別時需要加x字首,因為它們被對映到了為名為x的xml命名空間中 xmlns 與繪製ui相關的程式集。系統學習xaml語法 xaml是用於繪製ui的語言,借助它可以把ui定於與執行邏輯分離開,使用標籤來定義ui元素,...

SQLite的簡單封裝

studenttool.h sqlite的封裝 學生資料的crud import class student inte ce studenttool nsobject bool addstudent student student 獲得所有學生 return 陣列中裝著都說student模型 nsa...

MBProgressHUD的簡單封裝

下面是依據mbprogresshud分類提供的類方法 顯示一般資訊 void show nsstring text icon nsstring icon view uiview view 顯示有偏移量的資訊,yoffset,xoffset可以設定為0.f void showhint nsstring...