用于保存颜色信息的字段 [英] Which field to use for saving color information

查看:97
本文介绍了用于保存颜色信息的字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我上课了

Hi All,

I have a class

public class Lane
{
      public int Number { get; set; }

      public Color Colour { get; set; }
}


该模型是MVVM应用程序的一部分.

我需要记录车道的颜色,并且想知道哪种类最适合使用,以便可以在屏幕上将颜色显示为控件背景中的实际颜色以及该颜色的文本名称(例如红色).

我要使用颜色还是更好地使用画笔?

如何重新获得颜色名称?

人们推荐我使用哪种颜色选择器.我现在尝试了几次,它们返回画笔(这使我使用它)而不是颜色对象.


Which is the model as part of a MVVM application.

I need to record the color of the lane and was wondering which class is the best to use so that the color can be displayed on the screen as both the actual color in a background to a control and the text name of the color eg Red.

Do I use color or am I better of using a brush?

How do I get the name of the color back again?

which color picker do people recommend I use. I''ve tried a few now and they return brushes (which makes me what to use that) instead of a color object.

推荐答案

您的问题是您的财产颜色不会改变图形中的任何内容.您为什么认为发明了财产机制?主要是因为吸气剂和事件的副作用,更重要的是隐藏在简单的作业外观后面的二传手:

Your problem is that your property color does not change anything in graphics. Why do you think property mechanism was invented for? Mostly for side effect of the getter and event more importantly of the setter hidden behind the simple facade of assignment:

public class Lane
{
      //...
      public Color Colour {
          get { return GetColor(); }
          set { SetColor(value); } //change color of what''s inside
      }
}



现在,ColorBrush.如果您需要提供机会以非均一的颜色绘画,则只需使用Brush,否则即使在内部使用BrushColor也更好.封装并向外部用户隐藏不必要的复杂性.

请参见 http://en.wikipedia.org/wiki/Facade_pattern [



Now, Color vs Brush. If you need to provide the opportunity to paint something not in a single uniform color, you just have to use Brush, otherwise Color is better even if inside you use a Brush. Encapsulate and hide unwanted complexity from the outside user.

See http://en.wikipedia.org/wiki/Facade_pattern[^].

—SA


这篇关于用于保存颜色信息的字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆