【问题标题】:Brush editor in wpfwpf中的画笔编辑器
【发布时间】:2017-06-02 00:52:32
【问题描述】:

我有一个具有画笔属性的类,在我的 wpf UserControl 中有一个它的列表。当我想改变它的值时,它没有任何编辑器可以改变。它认为应该存在像 Category("Appearance") 这样的方法来启用编辑器,但我找不到它:( .

这是我的代码:

 using System.Collections.Generic;
 using System.ComponentModel;
 using System.Windows.Controls;
 using System.Windows.Media;

 namespace Tests
 {
     public partial class UserControl1 : UserControl
     {
         List<TestBrush> brushList;
         public List<TestBrush> BrushList
         {
             get{return brushList;}
             set{brushList = value;}
         }
         public UserControl1()
         {
             InitializeComponent();
         }
     }


     /// <summary>
     /// Test Brush Class
     /// </summary>
     public class TestBrush
     {
         Brush myBrush=Brushes.Aquamarine;

         [Category("Appearance")]
         public Brush MyBrush
         {
             get{return myBrush;}
             set{myBrush = value;}
         }
     }
 }

当我想改变时,我会看到:

UserControl BrushList Property (image)

我想要这样的东西:

BrushEditor (image)

【问题讨论】:

    标签: c# wpf user-controls brush


    【解决方案1】:

    尝试将其放在“画笔”类别下:

        [Category("Brush")]
        public Brush myBrushProperty { get; set; } = Brushes.Black;
    

    它应该与颜色选择器小部件和其他需要它的属性一起出现在顶部。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-23
      相关资源
      最近更新 更多