I'm creating a CategoryEditor for a UserControl. So my solution is made up of:
- UserControlProject
- UserControlProject.Design
- TestProject
My CategoryEditor should show a Button in the Property Grid for the category called "Common". The problem is that when I open the "Common" category for the UserControl placed in TestProject, Visual Studio hangs or I can't browse the Property Grid cause it's freezed.
This is my code (the most important parts):
The Category Editor:
internalclassQueryPropertyEditor:CategoryEditor{privateDataTemplate _dataTemplate;publicQueryPropertyEditor(){}publicoverride bool ConsumesProperty(PropertyEntry propertyEntry){//return propertyEntry.PropertyName == "Query" || propertyEntry.PropertyName == "OpcSession" || propertyEntry.PropertyName == "MaxRowsPerPage";returntrue;}publicoverrideDataTemplateEditorTemplate{
get {return _dataTemplate ??(_dataTemplate =newDataTemplate{VisualTree=newFrameworkElementFactory(typeof(QueryEditorButton))});}}publicoverrideobjectGetImage(Size desiredSize){returnnull;}publicoverridestringTargetCategory{
get {return"Common";}}}
Metadata.cs:
internalclassMetadata:IProvideAttributeTable{// Accessed by the designer to register any design-time metadata.publicAttributeTableAttributeTable{
get{AttributeTableBuilder builder =newAttributeTableBuilder();
builder.AddCustomAttributes(typeof(Col.HMI.Controls.Summary),newEditorAttribute(typeof(QueryPropertyEditor),typeof(QueryPropertyEditor)));return builder.CreateTable();}}}
The QueryEditorButton.xaml:
<UserControl x:Class="ColScadaControls.Design.QueryDesigner.QueryEditorButton"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"><StackPanel><TextBlockMargin="16,0"><HyperlinkClick="EditQueryClick">EditQuery...</Hyperlink></TextBlock></StackPanel></UserControl>
The QueryEditorButton.xaml.cs:
[ToolboxBrowsable(false)]publicpartialclassQueryEditorButton{publicQueryEditorButton(){InitializeComponent();}
}