DataTemplate for ValueTemplate binds to value from NameTemplate?

Grids for WPF Forum

Posted 10 years ago by Rick Andersen
Version: 14.1.0601

I'm new to Actipro controls (and fairly new to WPF), so this is very possibly (and hopefully) a naïve mistake on my part.

I'm trying to customize the control used for editing the value of a bound property, so I'm using the PropertyGridPropertyItem.ValueTemplate element in my XAML. However, the value I'm binding to within this template appears to be the same value that appears in the NameTemplate (i.e. the label).

Here's a simplified sample:

<propgrid:PropertyGridPropertyItem DisplayName="Version" Value="{Binding Version}" />

<propgrid:PropertyGridPropertyItem DisplayName="VersionX" Value="{Binding Version}" >
            <Label Content="{Binding}" />

The first item (Version) displays correctly, showing the value of the Version property of the bound object.

The second item (VersionX) I would have expected to either:
1. display the value of the VersionX property, or
2. display nothing until the binding was changed to "{Binding Version}".

Instead, it displays the label "VersionX" as both the name and the value. If I use "{Binding Version}", nothing is displayed. I've tried other bindings, but can't find anything that displays the value.

Can someone show me the correct way to do this? Or is this a bug?

Comments (4)

Answer - Posted 10 years ago by Actipro Software Support - Cleveland, OH, USA

Hi Rick,

Check out the Property Editors QuickStart source code since it shows how to make ValueTemplates.  You need your binding to look like this instead:

{Binding Value, RelativeSource={RelativeSource AncestorType={x:Type propgrid:IPropertyDataAccessor}}, Mode=TwoWay}

That will locate the IPropertyDataAccessor for which the property editor has been created and will bind to its Value.

Actipro Software Support

Posted 10 years ago by Rick Andersen

Wow!  That's extremely obtuse.  So easy to access the associated label, but so difficult to access the associated property.  

My example was actually simplified in that I actually need to access both the bound property and a second property of the bound object.  Any way to access that object?  

Posted 10 years ago by Actipro Software Support - Cleveland, OH, USA

Hi Rick,

Yes, there's a complex data model that is behind the scenes. :)  You can get at a different sibling property with a binding like this:

{Binding DataContext.Target.SiblingPropertyNameHere, RelativeSource={RelativeSource AncestorType={x:Type propgridPrimitives:IPropertyDataAccessor}}

Actipro Software Support

Posted 10 years ago by Markus Springweiler

I just wanted to report this, too. I used Snoop and saw that just 1 or 2 levels up the DataContext was a reasonable object type (PropertyGridPropertyItem?) when it suddendly becomes just a simple System.String, containing the name. Looks wrong to me, sorry guys.

The latest build of this product (v24.1.2) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.