Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
First, the article outlines
This presentation describes how to define WPF resources in a separate file, and calls the associated resource files where needed.Downloads (code and screen recording) : http://pan.baidu.com/s/1sjO7StB
online play : http://v.youku.com/v_show/id_XODExODg0MzIw.html
Tips : If the video screen and the code does not work download station can leave a message or email to [email protected]
two, first defined in a separate file resources
XAML code as follows:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib">
<sys:String x:Key="text">路漫漫其修远兮,吾将上下而求索!</sys:String>
</ResourceDictionary>
Third, where the resources are connected to a separate resource file
XAML code as follows:
<Window x:Class="Demo009.MainWindow"
xmlns="http://sche1mas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Resource Files" FontSize="30">
<Window.Resources>
<ResourceDictionary Source="ShinyRed.xaml" />
</Window.Resources>
<StackPanel>
<TextBlock Text="{StaticResource text}" />
</StackPanel>
</Window>
Code according to the above operation, even get!