在WPF中,有着兩種資源:
(1)第一種是:元件資源,又被稱為程式集資源,以二進制存在編譯後的程式集中,通常用于存放圖檔或其他音頻檔案。不恰當的說,就是WPF控件所需要的一些“圖檔”、“顔色”等資源。例如,Image控件:
<Image x:Name="img" Source="\ImgSource\a.jpg"/>
(2)第二種是:對象資源,通常放于xaml中。比如WPF的樣式(Style)、控件模闆(ControlTemplate)、資料模闆(DataTemplate),甚至可以是“普通”執行個體(例如:BitmapImage 或 自定義類)
對于“普通”執行個體的情況,特舉例如下:
元素==執行個體
(1):BitmapImage類
<BitmapImage UriSource="/FounderAMP;component/Images/Alarm/blue_press.png" x:Key="BlueLamp_Active"/>
<BitmapImage UriSource="/FounderAMP;component/Images/Alarm/green.png" x:Key="GreenLamp_Inactive"/>
<BitmapImage UriSource="/FounderAMP;component/Images/Alarm/green_press.png" x:Key="GreenLamp_Active"/>
(2)alarm命名空間下的3個自定義類
<alarm:AlarmStateToImage x:Key="s2i"/>
<alarm:IsImportTrackToImage x:Key="t2i"/>
<alarm:IsExitCoordinateToImage x:Key="c2i"/>