资源文件内的属性能否直接通过绑定应用到控件?答案是肯定的。
比如,我们要直接把下面的<SolidColorBrush x:Key="RedBrush" Color="#FFFF0000" />直接绑定到一个TextBlock的Foreground属性。
<Application x:Class="StaticResourcesWithBinding.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="Window1.xaml">
<Application.Resources>
<SolidColorBrush x:Key="RedBrush" Color="#FFFF0000" />
</Application.Resources>
</Application>
办法是直接把资源文件内的Key的名字绑定到控件,
public class MyViewModel
{
public string MyResourceKey { get; private set; }
public MyViewModel(