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'll start by saying I'm a bit of a WPF neophyte - still getting my head around some of the complexities - however I've tried a few things to do the following and I can't quite find something that feels right. In short, I want to structure my code thusly:
MyGenericPropertyGridControl will define a number of custom TypeEditors for my application's business objects, then will be re-used in multiple places in my application by including it in multiple places (MyApplicationUserControl, MyOtherApplicationUserControl, etc) I have used binding just fine to expose the underlying mindscape control's SelectedObject property through MyGenericPropertyGridControl, but I'm getting tripped up trying to assign Editors to the grid from multiple places. I've tried a few options (binding to the collection, creating a new collection and re-implementing changes to the underlying collection) but nothing feels like it's "the WPF way". So to be clear, I'd *LIKE* to be able to attach a bunch of editors in XAML in two places at once (generic ones in MyGenericPropertyGridControl and specific ones in MyApplicationUserControl). Any clues from the gurus out there? |
|
|
Can I clarify what you're trying to do here? It sounds like you want to write a control called MyGenericPropertyGridControl, which is basically the Mindscape grid with some extra "built-in" editors, and use that in other windows and user controls as follows: <app:MyApplicationUserControl> But in addition to that you want to use XAML to add the "built-in" editors to MyGenericPropertyGridControl, e.g.: <UserControl x:Class="MyLib.MyGenericPropertyGridControl"> Is that correct? If so, are you building MyGenericPropertyGridControl as a UserControl or a custom control? If not, could you say a bit more about your desired usage and how (in your ideal world) you'd like your XAML to look? Thanks! |
|
|
That is entirely correct (and apologies for not being clearer - sanitising internal code for forums is always a pain). At the moment I'm trying to avoid building a custom control unless it turns out to be necessary, so I'm creating MyGenericPropertyGrid as a UserControl. MyGenericPropertyGrid has a dependency property called SelectedObject, which is bound in XAML to the underlying ms:PropertyGrid control's SelectedObject. *Ideally* I'd just repeating that trick and bind to the Editors collection - but I don't think that's particularly feasible given that I'd like to effectively be defining entries for the editors collection in two different places. |
|
|
Yeah, I'm not optimistic about building the Editors collection on the underlying Mindscape grid through binding. Editors isn't a dependency property so it can't be bound. You could try hacking around it with a OneWayToSource binding, but I'd still be doubtful because I have a feeling that would try to set the value of the Editors property (which is read-only) rather than adding things to the collection. One thing you could try is just surfacing the Editors collection in code i.e.: partial class MyGenericPropertyGrid : UserControl (where _myGrid is the user control's instance of the Mindscape grid). Then when a consumer of your user control adds things to the user control's Editors collection, it's actually adding them to the "real" grid's Editors collection. I haven't tested this but it seems like it should work. Could you give it a go and let me know how it works out? If it doesn't work I'll see what else I can think of. |
|
|
I've just given the "just re-surface the Editors property" solution a quick go, and it's working nicely for me. Let me know if you run into any problems. |
|
|
Thanks! That works perfectly and is simple, elegant, and something that *should* have been self evident to me. I guess when all you have is a binding every problem looks like a nail.... or something :)
|
|