silverlight control創(chuàng)建過程解析
微軟在UI領(lǐng)域中正在逐漸的展現(xiàn)其的作用。silverlight的推出就是一款跨平臺(tái)的多媒體處理工具??梢詭椭绦騿T實(shí)現(xiàn)許多功能。我們?cè)谶@里先來了解一下silverlight control相關(guān)概念。#t#
在做控件的Template的時(shí),有可能需要用到位圖。但是直接把圖片放到silverlight control中去,在編譯運(yùn)行時(shí)會(huì)有xamlprase錯(cuò)誤。 這是控件沒有找到圖片資源報(bào)的錯(cuò)誤。圖片正確的寫法應(yīng)該是這樣:
- < 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();
- }
- }
上面就是我們?yōu)榇蠹医榻B有關(guān)silverlight control相關(guān)創(chuàng)建方法。