静态资源( StaticResource )指的是在程序载入内存时对资源的一次性使用,之后就不再访问这个资源了;动态资源(DynamicResource)使用指的是在程序运行过程中然会去访问资源。
简单的可以理解为,如果换皮肤而不重启程序,就需要用 DynamicResource
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" Title="MainWindow" Height="450" Width="800">
namespace WpfApp1
{
///
/// MainWindow.xaml 的交互逻辑
///
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Update_Click(object sender, RoutedEventArgs e)
{
this.Resources["PrimaryColorBrush"] = new SolidColorBrush(Colors.Red);
}
}
}
参考阅读
发表评论