). How can you set the default size with which the Popup Editor shows up when you invoke it from a Property Grid.
This is for everybody who is familiar with Windows Forms' Property Grid Editor.
You know that if you throw a List property to a Grid, it shows the little [...] button which if you press it pops up its default sub-value editor. I actually use the editor for another type of object, but I gave this example just so you know what I'm referring to. And here's a picture, at least until the link lives:
http://www.perpetuumsoft.de/sf/en/ims/rssSilverlight/GetStart/image032.jpg
My understanding is that (both for modal and non-modal editors) it is completely up to the whim of the control being shown. If the UITypeEditor involved chooses a big form, it will be big...
The only way to change that would be to define your own UITypeEditor and associate it with the types involved (sometimes possible with TypeDescriptor.AddAttributes(...), that creates the same form as the runtime wanted to show, but resizes it before showing.
You can achieve this by inheriting from the standard System.ComponentModel.Design.CollectionEditor and then set the desired size in the CreateCollectionForm override.
Decorate your collection to use the custom collection editor.
Below is an example that will start up the collection editor in full screen
class FullscreenCollectionEditor : System.ComponentModel.Design.CollectionEditor
{
protected override CollectionForm CreateCollectionForm()
{
var editor = base.CreateCollectionForm();
editor.WindowState = System.Windows.Forms.FormWindowState.Maximized;
return editor;
}
public FullscreenCollectionEditor(Type type) : base(type)
{
}
}
And then decorate your collection property with [Editor(typeof(FullscreenCollectionEditor), typeof(UITypeEditor))] i.e.
public class MyModel
{
[Editor(typeof(FullscreenCollectionEditor), typeof(UITypeEditor))]
public List<FileModel> Files { get; set; }
}
Related
I'm trying to get access to the properties shown by the properties window when a WPF control is selected.
The problem is that although I've managed to add my own content in the properties window, I have not found a way to obtain a reference to the one used by the WPF designer to display control properties.
private IVsWindowFrame _frame;
...
if(_frame == null) {
var shell = parent.GetVsService(typeof(SVsUIShell)) as IVsUIShell;
if(shell != null) {
var guidPropertyBrowser = new Guid(ToolWindowGuids.PropertyBrowser);
shell.FindToolWindow(
(uint) __VSFINDTOOLWIN.FTW_fFindFirst, ref guidPropertyBrowser, out _frame
);
}
}
As you can see I already have a reference to the Properties Window but unfortunately I have no idea how to get the properties listed.
In case it's relevant the reason I'm trying to do this is because I want to remove(or hide) some properties shown for the WPF controls in the designer.
Design-time support for WPF controls is based on public properties and attributes. Any public property of control is shown in properties window, but you may change visibility by attributes. There is a simple trick for hide existing property. You must define new property vith same name and add attributes. Is property is defined as virtual you could simply override but you could use keyword new.
Sample code:
public partial class MyUserControl : UserControl
{
public MyUserControl()
{
InitializeComponent();
}
[System.ComponentModel.Browsable(false)]
public new Brush Background
{
get { return base.Background; }
set { base.Background = value; }
}
}
Design-Time Attributes and Inheritance
When you derive a component or control from a base component that has design-time attributes, your component inherits the design-time functionality of the base class. If the base functionality is adequate for your purposes, you do not have to reapply the attributes. However, you can override attributes of the same type or apply additional attributes to the derived component. The following code fragment shows a custom control that overrides the Text property inherited from Control by overriding the BrowsableAttribute attribute applied in the base class.
See MSDN, you have to use BrowsableAttribute. Base concept is for WinFors and WebForms, but WPF controls have the same.
Can you please check How to enumerate all dependency properties of control?
I think this will help you for what you are looking for...
Regards,
I am trying to add some fields to a custom UserControl that I am making. I have some fields that I like them to be visible in the Properties window of Visual Studio. I tried to use the flags below but I dont see the field in the designer, even after a compile.
How should I do this correctly?
public partial class TosChartControl: UserControl
{
#region PUBLIC FIELDS
[Browsable(true)] //Added this but still does not show up
[Category("Data")]
[DefaultValue(0)]
[Description("ID of the Sensor Node")]
public int NodeId { get; set; }
#endregion
public TosChartControl()
{
InitializeComponent();
}
}
I did clean and rebuild the soloution and projects but I cant still see this field in Properties window. Even restarting the Visualstudio didnt help.
UPDATE: Your public properties are visible in the designer only when it's in another control in the designer. It turns out that you don't need to add this attribute, properties are visible by default in the designer. As far as I understand, when it's in another component's design view, an instance of the user control is created and properties can be shown. Sorry for misleading you in the beginning, I thought it was necessary to add it.
Try this attribute:
[Browsable(true)]
http://msdn.microsoft.com/en-us/library/system.componentmodel.browsableattribute.aspx
To elaborate on henginy's updated answer:
Be sure that you are looking at an instance of the control you want to modify properties for, and not the definition of the control itself.
To clarify, when you add a property to your TosChartControl class, you won't see the property in the TosChartControl.cs [Design] tab, you will see it where you implement a TosChartControl, such as your Form1.cs [Design] tab, e.g. the containing control to which you have added your custom control.
...Assuming that your Properties window is visible, and that you have the control selected.
What to take away from this lesson:
Understanding what the properties window is actually showing you — It's contextual.
The difference between the model and the implementation of the model — e.g. Designing the custom control and designing the form that uses the custom control.
Consider a form with some custom UserControl and a Button.
In Visual Studio designer, you can click the button off to the right of your property (like you would when you change other common properties on controls such as Font or Image) and use the Editor for this property.
During runtime, if you've added a PropertyGrid to the form and point it to this UserControl, you can also click the button off to the right of that complex property at runtime and get the same UITypeEditor dialog.
How can I get this editor window to come up during run-time through say, a button click without having a PropertyGrid on the form?
Though I've gotten the PropertyDescriptor and the UITypeEditor from this descriptor, I don't know what to call to get the instances of ITypeDescriptorContext and IServiceProvider when calling UITypeEditor.EditValue to get the editor to display.
This is related to building a custom UITypeEditor for a property: Building Windows Forms Controls and Components with Rich Design-Time Features. In this case, I've already configured all of this and it all works beautifully so I just want to call the editor window at runtime.
I you had managed to implement a TypeDescriptor, you almost done.
This may be a start for you:
public class MyEditor: UITypeEditor {
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context) {
return UITypeEditorEditStyle.DropDown;
}
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) {
IWindowsFormsEditorService service = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
if (service != null) {
SomeControl ctrl = new SomeControl();
ctrl.XYZ = ...
service.DropDownControl(ctrl);
value = ctrl.XYZ;
}
return value;
}
WinForms handles the rest of it.
Return UITypeEditorEditStyle.Modal form GetEditStyle and also use service.ShowDialog(ctrl), if you have a form instead of a control.
Hi Experts
I create an user control in windows application.
when it inherits from Control base class it would have many events and properties that may be not uses in usercontrol and I what to hide then in Properties Window.
How I can do this?
thanks
use the following 3 attributes on the events or properties:
when you cannot override the property, just replace 'override' with 'new'. The EditorBrowsable attribute has no effect on the properties window, but on the code editor.
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
[EditorBrowsable(EditorBrowsableState.Never)]
public override Color BackColor
{
get
{
//implementattion
}
set
{
//implementation
}
}
If i have understood properly, then you should change the accessor level base control methods and events to private which you want to hide from child class.
I am writing a control for c# (WinForms) and I have one property of Collection type.
When user select this property, button with "..." will be shown and new modal dialog will open. All this work fine, I have create:
public class ItemsEditor : UITypeEditor
In this class I have override EditValue method and open modal editor with ShowDialog. As I say this work fine.
But, I want to open this dialog when user of control double-click on it.
For this purpose I have inherit ControlDesigner:
public class MyControlDesigner : ControlDesigner
and in this class I have inherit next method:
public override void DoDefaultAction()
{
string propertyName = "Items";
IServiceProvider provider = (IServiceProvider)GetService(typeof(IServiceProvider));
PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(MyControl);
PropertyDescriptor property = properties[propertyName];
UITypeEditor editor = (UITypeEditor)property.GetEditor(typeof(UITypeEditor));
editor.EditValue(provider, null);
}
As may be seen, I have put some random code and of course don't work.
Can somebody help me how to solve this, and how to open property on double-click.
Thank you for all help
Best regards
Bojan
I am not certain about feasibility of showing the editor on double click but one of other way could be using ActionLists aka SmartTag - please see article: http://msdn.microsoft.com/en-us/library/ms171829.aspx