Showing posts with label System Brushes List. Show all posts
Showing posts with label System Brushes List. Show all posts

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.