日期:2014-05-17  浏览次数:20706 次

WPF,这种资源怎么创建?
类中的一个静态成员:
namespace WPF2
{
    class Brushs
    {
        public static SolidColorBrush brush { get; set; }
        static Brushs()
        {
            brush = .......;   
        }
    }
}

请问,如何在XAML中创建一个SolidColorBrush资源,引用Brushs中的静态SolidColorBrush
<Window.Resources>
    <SolidColorBrush ........."/>
</Window.Resources>


该怎么写?

------解决方案--------------------
http://www.cnblogs.com/lxy131/archive/2010/08/26/1808986.html
------解决方案--------------------
你想要做什么?动态设定Resource?
这种情况下要用binding的。
------解决方案--------------------

using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows.Media;

namespace WpfStaticResource
{
    class CustomBrush : INotifyPropertyChanged 
    {
        private SolidColorBrush _myBrush;

        public SolidColorBrush MyBrush
        {
            get
            {
                return _myBrush;
            }
            set
            {
                if (_myBrush != value)
                {
                    _myBrush = value;
                    NotifyPropertyChanged();
                }
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
        {
            if (Proper