XML名称空间中不存在Readonly DependencyProperty

时间:2014-06-05 08:06:16

标签: c# wpf dependency-properties

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

我在XAML上收到以下错误

  

XML中不存在“DesignTimeHelper.DesignTimeData”属性   namespace'clr-namespace: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>

    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);
            }
        }
        }
    }

为什么DependencyProperty现在不工作?它需要任何其他依赖吗?

请分享您的想法。

由于

0 个答案:

没有答案