I have a custom user control ( 'InventoryImageBtn' ) that I'm embedding in an unboud field of my XamDataGrid. I bind it's source to a bound field that contains a path to an image if it exists (in this case the control displays the image), if not it just contains an '0' (in which case the control displays an 'upload' image button.
The control has a dependency property named 'Index' that I want to bind to the Record.Index that the control gets placed in. Can you tell me the correct syntax for binding to this property?
The CellValuePresenter style for the control:
<Style TargetType="{x:Type igDP:CellValuePresenter}" x:Key="ImgBtnField">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}">
<local:InventoryImageBtn x:Name="ImageBtn" ButtonMode="Image" Index="{Binding Record.Index}" ImageSource="{Binding Cells[Image].Value}" Width="75" Height="75"/>
<ControlTemplate.Triggers>
<DataTrigger Binding="{Binding Cells[Image].Value}" Value="0">
<Setter TargetName="ImageBtn" Property="ButtonMode" Value="Button"/>
</DataTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Would setting the DataContext get me there? How?
Hello,
The data context of the CellValuePresenter is the DataRecord, so a valid binding to the index of the record would be Path=Index.
Another way would be to use Record.Index as you have done, but set the RelativeSource to TemplatedParent as well -> Path=Record.Index, RelativeSource={RelativeSource TemplatedParent}