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
|
Hello! I would like to know if somebody has edited a property of Uri type. In my application, I have a CLR-class which has a property named MyUri of type Uri. <ms:PropertyGrid Name="_properties" SelectedObject="{Binding}" > <local:UriConverter x:Key="UriConverter" /> <DataTemplate x:Key="UriEditor"> and the UriConverter code is: class UriConverter : IValueConverter It doesn't work when I write an existing filename in DataTemplate's TextBox. But, when I put my ms:TextBox in a Window, like a simple control, it works! I.e., it doesn't work when TextBox is inside the grid. Any help?
Thanks. |
|
|
Hello Josep, The reason this is not working is that your DataTemplate is receiving a Uri object and is trying to bind to the MyUri property of that object. A TypeEditor on a reference type passes the referenced object, so that the template can bind directly to the properties of that object; see the PhoneNumber example in the Editors sample and note how the text boxes bind to the CountryCode, etc. properties. Instead, you need to use a PropertyEditor. A PropertyEditor allows you to reference the entire passed object as if it were a property called Value: <DataTemplate x:Key="UriEditor"> <ms:PropertyEditor DeclaringType="..." PropertyName="MyUri" EditorTemplate="{StaticResource UriEditor}" /> If you have lots of properties of type Uri, and/or don't want to name the properties explicitly, you'll need to get a recent nightly build. TypeEditor now has a TemplateBindingMode property. By setting TemplateBindingMode="WrappedValue" then you can get the PropertyEditor-style behaviour in a TypeEditor, which is useful for immutable reference types like Uri. (If you don't like using nightlies, you can get the same effect in the RTM version, but you'll have to write a smart editor declaration -- see http://www.mindscape.co.nz/blog/index.php/2008/04/30/smart-editor-declarations-in-the-wpf-property-grid/ for details.) |
|