WPF 依赖属性的使用

介绍:

依赖属性可以为控件增加一个自定义属性。依赖属性可以在XAML和ViewModel中自由使用。

1.创建一个自定义类,增加一个依赖属性

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace CMNWorkStation.Common
{
    public class RichBorder : Border
    {
        //增加依赖属性
        public bool IsSelected
        {
            get { return (bool)GetValue(IsSelectedProperty); }
            set { SetValue(IsSelectedProperty, value); }
        }

        public static readonly DependencyProperty IsSelectedProperty =
            DependencyProperty.Register("IsSelected", typeof(bool), typeof(RichBorder));
 

你可能感兴趣的:(WPF,wpf)