ResourceDictionary.Source 屬性

定義

取得或設定要從中載入資源的的統一資源識別項 (URI)。Gets or sets the uniform resource identifier (URI) to load resources from.

public:
 property Uri ^ Source { Uri ^ get(); void set(Uri ^ value); };
public Uri Source { get; set; }
member this.Source : Uri with get, set
Public Property Source As Uri

屬性值

Uri

外部資源字典的來源位置。The source location of an external resource dictionary.

範例

下列範例會指定兩個 ResourceDictionary 要合併到主要的元素 ResourceDictionaryThe following example specifies two ResourceDictionary elements to be merged into the primary ResourceDictionary.

<Page.Resources>
  <ResourceDictionary>
    <ResourceDictionary.MergedDictionaries>
      <ResourceDictionary Source="myresourcedictionary.xaml"/>
      <ResourceDictionary Source="myresourcedictionary2.xaml"/>
    </ResourceDictionary.MergedDictionaries>
  </ResourceDictionary>
</Page.Resources>

備註

一般而言, Source 會指定為 PACK URI,它會參考您的應用程式建立專案所包含作為 Noncompiled 資源或內容組建動作之資源字典的位置。Typically, Source is specified as a Pack URI, which references the location of a resource dictionary that is included as a noncompiled Resource or Content build action by your application building project. 如需套件 URI 格式的詳細資訊,請參閱 WPF 中的套件 uriFor details on the Pack URI format, see Pack URIs in WPF.

一般而言, Source 屬性只會針對屬性所指定的設定, ResourceDictionary MergedDictionaries (做為 XAML 中的屬性專案,或是程式 ResourceDictionary 代碼) 中之集合的專案。Generally, the Source property is set only for a ResourceDictionary that is specified for the MergedDictionaries property (either as a property element in XAML, or as a ResourceDictionary item of the collection in code). 在此內容中,設定的值 Source 會將在提供的 URI 找到的字典內容合併到目前的 ResourceDictionaryIn this context, setting the value for Source will merge the dictionary contents found at the supplied URI into the current ResourceDictionary. 任何載入失敗都會導致擲回例外狀況。Any load failures will cause an exception to be thrown.

適用於

另請參閱