Wednesday, January 9, 2008

How Can I Get System Brushes List in WPF?.

For getting System brushes list, we need to use propertyinfo class.

Here i am creating ObservableCollection with object type as MyBrush.

public class ColorItemList: ObservableCollection
{
public
ColorItemList() : base()
{
Type type = typeof( Brushes );
foreach( PropertyInfo propertyInfo in type.GetProperties( BindingFlags.Public BindingFlags.Static ) )
{
if( propertyInfo.PropertyType == typeof( SolidColorBrush ) )
Add( new MyBrush( propertyInfo.Name, ( SolidColorBrush )propertyInfo.GetValue( null, null ) ) );
}
}
}

MyBrush.CS class should be like this.

public class MyBrush
{
private string m_name;
private SolidColorBrush m_brush;
public string Name
{
get
{
return m_name;
}
set
{ m_name = value;
}
}
public SolidColorBrush Brush
{
get
{
return m_brush;
}
}
public MyBrush(string name, SolidColorBrush brush )
{
m_name = name;
m_brush = brush;
Color color = brush.Color;
}
}

Now you can get System brushes list using our IEnumerable class MyBrushList.

I hope you may got idea. if not Please don't hesitate to post your comments here.

3 comments:

  1. Hello. This post is likeable, and your blog is very interesting, congratulations :-). I will add in my blogroll =). If possible gives a last there on my site, it is about the CresceNet, I hope you enjoy. The address is http://www.provedorcrescenet.com . A hug.

    ReplyDelete
  2. Hi,

    In the post I see class ColorItemList and constructor MyBrushList() for this class. I guess the code needs to be changed. Just a general feedback.

    ReplyDelete
  3. Hi,

    Thanks for brought up the mistake into my attention.

    ReplyDelete