Avoiding Visual Studio designer errors when WPF resource is defined in separate project

前端 未结 3 1078
[愿得一人]
[愿得一人] 2020-12-08 19:10

How can I avoid Visual Studio designer errors when a WPF resource is defined in separate project?

I have three projects in a composite WPF application: the main appl

3条回答
  •  情话喂你
    2020-12-08 19:46

    I just want to extend Simon D. answer. What he is proposing is the solution that i am using right now. I just wanted to share complete source code. It is from this Trick To Use A ResourceDictionary Only When In Design Mode source.

    public class DesignTimeResourceDictionary : ResourceDictionary
    {
        /// 
        /// Local field storing info about designtime source.
        /// 
        private string designTimeSource;
    
        /// 
        /// Gets or sets the design time source.
        /// 
        /// 
        /// The design time source.
        /// 
        public string DesignTimeSource
        {
            get
            {
                return this.designTimeSource;
            }
    
            set
            {
                this.designTimeSource = value;
                if ((bool)DesignerProperties.IsInDesignModeProperty.GetMetadata(typeof(DependencyObject)).DefaultValue)
                {
                    base.Source = new Uri(designTimeSource);
                }
            }
        }
    
        /// 
        /// Gets or sets the uniform resource identifier (URI) to load resources from.
        /// 
        /// The source location of an external resource dictionary. 
        public new Uri Source
        {
            get
            {
                throw new Exception("Use DesignTimeSource instead Source!");
            }
    
            set
            {
                throw new Exception("Use DesignTimeSource instead Source!");
            }
        }
    }
    
    
    
      
        
      
    
        
          
        
    
    

提交回复
热议问题