silverlight control創建過程解析
作者:佚名
silverlight control的創建過程在本文中將會以一段代碼為大家呈現在眼前,希望大家可以通過這篇文章介紹的內容提高編程效率。
微軟在UI領域中正在逐漸的展現其的作用。silverlight的推出就是一款跨平臺的多媒體處理工具。可以幫助程序員實現許多功能。我們在這里先來了解一下silverlight control相關概念。#t#
在做控件的Template的時,有可能需要用到位圖。但是直接把圖片放到silverlight control中去,在編譯運行時會有xamlprase錯誤。 這是控件沒有找到圖片資源報的錯誤。圖片正確的寫法應該是這樣:
- < Image Source="/MyControl;
component/nasa.png" />完整的Template
代碼如下:< ResourceDictionary - xmlns="http://schemas.microsoft.
com/winfx/2006/xaml/presentation" - xmlns:x="http://schemas.mic
rosoft.com/winfx/2006/xaml" - xmlns:vsm="clr-namespace:System.
Windows;assembly=System.Windows" - xmlns:my="clr-namespace:
MyControl;assembly=MyControl" - >
- < Style TargetType="my:MyQRCode">
- < Style.Setters>
- < Setter Property="Template">
- < Setter.Value>
- < ControlTemplate TargetType=
"my:MyQRCode"> - < Grid x:Name="Root">
- < Image Source="/MyControl;
component/nasa.png" /> - < /Grid>
- < /ControlTemplate>
- < /Setter.Value>
- < /Setter>
- < /Style.Setters>
- < /Style>
- < /ResourceDictionary>控件代碼:
public class MyQRCode : Control - {
- public MyQRCode() : base() {
- DefaultStyleKey = typeof(MyQRCode);
- }
- public override void OnApplyTemplate()
- {
- base.OnApplyTemplate();
- }
- }
上面就是我們為大家介紹有關silverlight control相關創建方法。
責任編輯:曹凱
來源:
博客園