Hello!
I want one of my columns to show a image and a TextEditor, the image should be able to change visability depending on valuechange in another column. I made a CellValuePresenterStyle to do this but the object i get is a DataRecord and I need to get to properties on the Cell.
Can someone help me with this please?
/Sara
<Style x:Key="CellStyle" TargetType="{x:Type igDP:CellValuePresenter}" BasedOn="{StaticResource SmallCellValueStyle}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Image x:Name="Image" Source=" ../../../../Resources/Orgchart.png" Visibility="Hidden"/>
<Editors:XamTextEditor Text="{Binding Path=Quantity}" />
<ControlTemplate.Triggers>
<DataTrigger Binding="{Binding Path=IsChildrenModified}" Value="True">
<Setter TargetName="Image" Property="Visibility" Value="Visible" />
</DataTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
The way you have written the style, you are expecting the MyPropertyOnTheCellObject to be the property of the CellValuePresenter. This is not the case. Since the Cell itself is not exposed (as I mentioned its lazily created) you would have to do something like:
<Editors:XamTextEditor Grid.Column="1" Text="{Binding Path=Record.Cells[YourFieldNameOrFieldIndexHere].MyPropertyOnTheCellObject}" >
Hi
Thanks for the answers but I'm afraid I still dont understand how I should do it.
This is my style, I'm trying to bind to the MyPropertyOnTheCellObject and MyOtherPropertyOnTheCellObject, but can´t find the cell object. How should I do the binding? Can I use the fieldname in the style?
<Style x:Key="CellStyle" TargetType="{x:Type igDP:CellValuePresenter}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="20" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Image x:Name="Image" Grid.Column="0" Source=" ../../../../Resources/Orgchart.png" Visibility="Hidden"/>
<Editors:XamTextEditor Grid.Column="1" Text="{Binding Path=MyPropertyOnTheCellObject}" >
</Editors:XamTextEditor>
<DataTrigger Binding="{Binding Path=MyOtherPropertyOnTheCellObject}" Value="True">
Edit: removed a modified copy of the style that accedently got added
I am sorry, I misunderstood the question.
Andrew Smith, thank you for correcting me.
I apologize again, I thought the goal was to get to the CellValuePresenter or the Editor.
Alex.
The associated Cell isn't currently exposed since the cells are lazily allocated but if this style is specific for a field then you can use the Record.Cells[fieldname] to get the cell.
Hello,
The fastest way to get to the CellValuePresenter from the code behind is maybe with the method CellValuePresenter.FromRecordAndField.
For example:
DataRecord dr = xamDG.ActiveRecord as DataRecord; CellValuePresenter cvpCombo = CellValuePresenter.FromRecordAndField(dr, dr.FieldLayout.Fields[1]); CellValuePresenter cvpText = CellValuePresenter.FromRecordAndField(dr, dr.FieldLayout.Fields[0]); XamComboEditor ce = cvpCombo.Editor as XamComboEditor; XamTextEditor te = cvpText.Editor as XamTextEditor;
Hope this helps,