C# XML命名空间中不存在只读DependencyProperty

C# XML命名空间中不存在只读DependencyProperty,c#,wpf,dependency-properties,C#,Wpf,Dependency Properties,安装visual studio 2008后,我现有的C#/WPF项目现在无法工作。但之前它在VisualStudio2008中运行良好 我在XAML上遇到以下错误 XML中不存在属性“DesignTimeHelper.DesignTimeData” 命名空间“clr命名空间:Monitor.Controls”。第13行位置5 请查找随附的xaml和cs文件 <UserControl xmlns="http://schemas.microsoft.com/winfx/

安装visual studio 2008后,我现有的C#/WPF项目现在无法工作。但之前它在VisualStudio2008中运行良好

我在XAML上遇到以下错误

XML中不存在属性“DesignTimeHelper.DesignTimeData” 命名空间“clr命名空间:Monitor.Controls”。第13行位置5

请查找随附的xaml和cs文件

    <UserControl
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"   
        xmlns:crl="clr-namespace:Monitor.Controls"
        xmlns:dat="clr-namespace:System.Windows.Data;assembly=PresentationFramework"
        xmlns:ui="clr-namespace:UIControls;assembly=UIControls"
        crl:DesignTimeHelper.DesignTimeData="{x:Type svm:SampleAlertsTabViewModel}"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d">

        ...
    </UserControl>
为什么DependencyProperty现在不起作用?它需要其他依赖项吗

请分享你的想法


谢谢

它在哪个VS中起作用,在哪个VS中不起作用?它在同一个组件中吗?显示您的
xmlns
声明。您是否也声明了静态getter和setter方法,如图所示?是的,包括getter和setter方法。请查收。。
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.ComponentModel;
    using System.Windows;

    namespace Monitor.Controls
    {
        public static class DesignTimeHelper
        {
        public static readonly DependencyProperty DesignTimeDataProperty =
        DependencyProperty.RegisterAttached("DesignTimeData", typeof(Type), typeof(DesignTimeHelper), new FrameworkPropertyMetadata(null, new PropertyChangedCallback(OnDesignTimeDataChanged)));

        public static Type GetDesignTimeData(DependencyObject obj)
        {
            return (Type)obj.GetValue(DesignTimeDataProperty);
        }

        public static void SetDesignTimeData(DependencyObject obj, Type value)
        {
            obj.SetValue(DesignTimeDataProperty, value);
        }


        private static void OnDesignTimeDataChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var isOnDesignMode = DesignerProperties.GetIsInDesignMode(new DependencyObject());
            if (isOnDesignMode)
            {
            var element = d as FrameworkElement;
            if (element == null)
                throw new NullReferenceException("element must not be null and must be an UIElement.");

            var designTimeDataType = e.NewValue as Type;
            if (designTimeDataType == null)
                throw new NullReferenceException("designTimeDataType must not be null.");

            element.DataContext = Activator.CreateInstance(designTimeDataType);
            }
        }
        }
    }