This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
I saw the example of 'How do I add an ellipses button'. Is there any way to add the ellipses button in source code without using xaml. I have many objects to bind to a same PropertyGrid at different times. Ideally, I want to implement all the features in the source code without making data templates for each object in xaml. If not, would you like to implement these features in the next version of PropertyGrid. |
|
|
You have to add the ellipses button through a DataTemplate. DataTemplates are the way that the grid displays its UI for properties and there is no getting around this (at least not without extremely radical surgery). So if you absolutely must create the ellipses button in code, you'll have to create the DataTemplate in code. You can do this by using the FrameworkElementFactory class. However, it's very rarely necessary to do this, and just needing to bind different objects to the grid shouldn't require you to go to these lengths. Why not just create a single DataTemplate in XAML and reuse it for the different properties? If there are a lot of properties with different names that you want to share the same template, you can easily encapsulate this logic using a smart editor declaration: http://www.mindscape.co.nz/blog/index.php/2008/04/30/smart-editor-declarations-in-the-wpf-property-grid/ Here we are mapping all properties with the word "Image" in their name to the ellipses template but you could equally well do this by checking for an attribute or whatever your source code would have been doing. You can furthermore vary the behaviour of the template: the following post shows how to display different dialogs from the same ellipsis template depending on which property is being edited: http://www.mindscape.co.nz/blog/index.php/2008/12/11/smart-editors-for-the-wpf-property-grid-meet-smart-templates/ By the way, from your recent posts I have a feeling that you're trying to do some quite sophisticated stuff with dynamic metadata. If that's the case, we may be able to give you better advice if we understand the broader context of what you're trying to display and where the add/remove/enable/disable stuff fits in. No promises, but at the moment I feel we're trying to address specific implementation issues when there might be a simpler overall solution lurking at the design level. Just a thought! |
|
|
Hi Ivan, I was follwoing your article http://www.mindscape.co.nz/blog/index.php/2008/12/11/smart-editors-for-the-wpf-property-grid-meet-smart-templates/ [which is great by the way] and encountered a little problem.. When it comes to binding the tag property of the button in xml to the Value property, the Value property seems to be always set to null. After much playing around I found a temporary workaround by assigning "UnderlyingObject" property to the Tag and "PropertyName" to the ContentStringFormat, like so: Tag="{Binding UnderlyingObject}"
ContentStringFormat="{Binding PropertyName}" And then in code behind using reflection to querry the value of the property by name on the given object instance. Im sure Im doing something wrong in the relation to the datatemplate bit but cant figure out what it is. Any ideas? Any help is appreciated :) Thanks, Kyryll
|
|
|
Value certainly *should* contain the value of the property -- shouldn't be any need to retrieve it manually like this. Did you see any data binding errors? Could you post your smart editor code and your data template? |
|
|
< UserControl x:Class="PropertyGrid" xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml xmlns:mindpropgrid="clr-namespace:Mindscape.WpfPropertyGrid;assembly=Mindscape.WpfPropertyGrid"
xmlns:local="clr-namespace:mokom.workQ.workQStudio"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<UserControl.Resources>
<DataTemplate x:Key="PopupEditor">
<DockPanel>
<Button DockPanel.Dock="Right" Padding="-2"
Tag="{Binding Value}"
Click="TypeEditorPopup">...</Button>
<TextBlock Foreground="Black" Text="Click button to edit" />
</DockPanel>
</DataTemplate>
</UserControl.Resources>
<mindpropgrid:PropertyGrid Background="White" Name="PropertyGrid" DefaultMargin="0" Foreground="White">
<mindpropgrid:PropertyGrid.Editors>
<local:PropertyGridPopupEditor EditorTemplate="{StaticResource PopupEditor}" />
</mindpropgrid:PropertyGrid.Editors>
</mindpropgrid:PropertyGrid> </
UserControl> -------------------------------------------------------------------------------
Public Class PropertyGridPopupEditor
Inherits Mindscape.WpfPropertyGrid.ObjectWrappingEditor
Public Overrides Function CanEdit(ByVal node As Mindscape.WpfPropertyGrid.Node) As Boolean
Return node.Property.IsDefined(GetType(mokom.CommonObjects.TypeEditorAttribute), True)
End Function
Protected Overrides Sub SetContentTemplate(ByVal factory As System.Windows.FrameworkElementFactory, ByVal node As Mindscape.WpfPropertyGrid.Node) factory.SetValue(ContentControl.ContentTemplateProperty, EditorTemplate)
End Sub End
Class
--------------------------------------------------------------------------- In the event handler just doing this:
Dim EditObjectType As Object = CType(sender, Button).Tag leaves the EditObjectType = Nothing IF I change the binding in xml to be Tag="{Binding}", I can visualise in code the whole object wrapper and see that its Value is in fact Nothing and Underlyingobject property is pointing to the instance of the parent of my property and propertyname is set to the property being edited. I double checked and there are no binding errors during running of the code above. Very odd.. the only difference to the sample you have provided is that I have my classes scattered over many more projects but I doubt thats causing issues.. Will experiment a little more, maybe something will come up :) Thanks for your help, Kyryll |
|
|
Curious, that all looks fine. I can't see any reason why Value would be Nothing (unless of course the property value really is Nothing). It's not an indexed property is it? Visual Basic has different indexed property support from C# and looking at the code I wonder if that might cause a problem. Might be worth creating a simplified object and proving that it works on that, then build it up towards your real object to see where it goes wrong... |
|