Sunday, February 28, 2010

Property Grid Editing Support for Collection Type Property - Custom Control

Hi,

Last week I faced some problem while giving property grid editor support for collection type property. For instance my custom control(NavigationControl) inherited from ItemsControl and its item container is NavigationItem. Now when I try to add items through Items property in property grid(In both VS2008 and VS2010), Add button is in disabled state which is present in collection editor dialog box.

To activate this with custom type or collection of types, you can register this in attribute table builder of your designer projects.

For instance,

internal class Metadata : IRegisterMetadata
{

// Called by Cider to register any design-time metadata
public void Register()
{
AttributeTableBuilder builder = new AttributeTableBuilder();
builder.AddCustomAttributes(typeof(NavigationItem), new ToolboxBrowsableAttribute(false));
builder.AddCustomAttributes(typeof(NavigationControl), "Items", new NewItemTypesAttribute(typeof(NavigationItem)));
MetadataStore.AddAttributeTable(builder.CreateTable());
}
}


Thanks,
Venugopal.

Wednesday, February 10, 2010

How to set Enum type as ItemsSource?

Hi,

Here is the simple way to bind the Enum types as ItemsSource in items control.

<Window x:Class="DoubleTextBoxSample.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:DoubleTextBoxSample"
xmlns:syncfusion="http://schemas.syncfusion.com/wpf"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
Title="Window1" Height="300" Width="300">
<Window.Resources>
<ObjectDataProvider x:Key="itemsFromEnum" MethodName="GetValues" ObjectType="{x:Type sys:Enum}">
<ObjectDataProvider.MethodParameters>
<x:Type TypeName="Orientation"/>
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
</Window.Resources>

<StackPanel>
<syncfusion:CheckListBox ItemsSource="{Binding Source={StaticResource itemsFromEnum}}">
</syncfusion:CheckListBox>
</StackPanel>
</Window>


Just bound object provider instance with Syncfusion's CheckListbox ItemsSource property and got cool result.





Thanks,
Venugopal.