当前位置: 代码迷 >> Windows Mobile >> 关于 DependencyProperty 的一个有关问题
  详细解决方案

关于 DependencyProperty 的一个有关问题

热度:130   发布时间:2016-04-25 07:11:47.0
关于 DependencyProperty 的一个问题
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.DependencyProperty;

namespace ImageButton
{
    public class ImageButton : Button
    {
        public static readonly DependencyProperty ImageSourceProperty =
            DependencyProperty.Register(
                "ImageSource",
                typeof(ImageSource),
                typeof(ImageButton),
                null);

        public ImageSource ImageSource
        {
            get { return (ImageSource)GetValue(ImageSourceProperty); }
            set { SetValue(ImageSourceProperty, value); }
        }
    }
}


我要弄一个ImageButton的自定义控件,但是在网上找到一段代码,粘贴过去以后,红色部分一直报错,错误信息为:imagesource是一个属性,不能作为一个类型来使用,但是网上是这么搞得啊,请问如何解决。。。。。。

------解决方案--------------------
缺少引用了你点鼠标右键,有“解析”,系统会自己找到这个类的引用,如果没有,那就表示这个项目中所有引用的库都没这个类
------解决方案--------------------
 public static readonly DependencyProperty SourceProperty =
            DependencyProperty.Register(
                "Source",
                typeof(ImageSource),
                typeof(ImageButton),
                null);

        public ImageSource Source
        {
            get { return (ImageSource)GetValue(SourceProperty ); }
            set { SetValue(SourceProperty , value); }
        }