Hello,
I am using WPF NetAdvantage 2012.2 (and cannot update to a later version).
I have a xamdatagrid with an UnboundField defined. I need to apply a binding converter to this unbound field and need to pass in the DataItem itself (which seems straighforward) and the DataContext of the grid.
Can I have an example of how to do this? The trouble I am having is with getting access to the DataContext from the Unboundfield.
Thanks.
Hello Torque,
The UnboundField does not derive from FrameworkElement and its DataContext is not initially set. You can try using the following binding for the UnboundField if you would like to get the XamDataGrid’s DataContext
Binding="{Binding Path=Cell.DataPresenter.DataContext, RelativeSource={RelativeSource Self}}"
If you have any questions or concerns on the same do not hesitate to let me know.
Thanks. That binding works when I try to use a regular value converter.
Can you show me an example of a multi binding being used on an unbound field please?
Let's say we have a simple unbound field called "Prices". This field will contain doubles and I want to use a multi value converter, passing in the field's DataItem and the grid's DataContext, to set this field's value.
There is no need to use a namespace reference (igDP:) for the Binding Path. It can be <Binding Path="Cell.DataPresenter.DataContext" RelativeSource="{RelativeSource Self}"/>
I have put together and attached a simple project to illustrate it. Let me know if it does not meet your requirements.
I tried the below. The first <Binding> is fine but the second one results in an UnsetValue:
System.Windows.Data Warning: 40 : BindingExpression path error: 'igDP:Cell' property not found on 'object' ''ValueHolderWithDataContext' (HashCode=46875058)'. BindingExpression:Path=igDP:Cell.DataPresenter.DataContext; DataItem='ValueHolderWithDataContext' (HashCode=46875058); target element is 'ValueHolderWithDataContext' (HashCode=46875058); target property is 'Value' (type 'Object')
What do I need to change here?
<igDP:UnboundField Name="Sample" Label="Sample"> <igDP:UnboundField.Binding> <MultiBinding Converter="{StaticResource SampleConverter}"> <Binding/> <Binding Path="igDP:Cell.DataPresenter.DataContext" RelativeSource="{RelativeSource Self}"/> </MultiBinding> </igDP:UnboundField.Binding> </igDP:UnboundField>
Any examples on how to accomplish this?