I have been browsing the forum and this simple issue has many outdated and unavailable answers. I have a nice xamdatagrid with a couple of fields: EstatusGastoId and Id. The latter has some hyperlinks to change some values. I want to show only one of the commands depending on EstatusGastoId value, I tried this:
<igDP:TextField Name="EstatusGastoId" Label="Estatus" Width="100" IsReadOnly="True" /> <igDP:TemplateField Name="Id" Label="" HorizontalContentAlignment="Center" > <igDP:TemplateField.DisplayTemplate> <DataTemplate> <StackPanel Orientation="Vertical">
<TextBlock Margin ="5 0 0 0 "><Hyperlink Command="{Binding DataContext.RechazaGastoCommand,RelativeSource={RelativeSource AncestorType={x:Type igDP:XamDataGrid}}}" CommandParameter="{Binding}" > <TextBlock Text="Rechazar" TextDecorations="Underline" Foreground="Red" Visibility="{Binding EstatusGastoId,Converter={StaticResource EstatusToRechazarVisibilityConverter}}"/> </Hyperlink> </TextBlock >
<TextBlock Margin ="5 0 0 0 "> <Hyperlink Command="{Binding DataContext.CancelaRechazoGastoCommand,RelativeSource={RelativeSource AncestorType={x:Type igDP:XamDataGrid}}}" CommandParameter="{Binding}" > <TextBlock Text="Cancela Rechazo" TextDecorations="Underline" Foreground="Blue" /> </Hyperlink> </TextBlock >
</StackPanel> </DataTemplate> </igDP:TemplateField.DisplayTemplate> </igDP:TemplateField>
but it cannot find EstatusGastoId. I am sure it's something very silly but I cannot find any reference out there on how to do this. any suggestions?
Hi Enrique,
Thank you for posting to Infragistics Community!
What you are looking to achieve is definitely possible and could be approached in different ways.
To start with, I believe the following topics from our documentation will be helpful:
As the latter topic suggests, the DisplayTemplateSelector is a convenient API exposed to conditionally configure a display template.
Furthermore, to demonstrate yet another alternative, I am attaching a small sample here, where TextBlocks are conditionally rendered within a display template with the help of a DataTrigger. Optionally, a Converter class could be used to define a more complex condition for the binding. Please, note that this is rather a general WPF implementation question, though.
The sample also demonstrates an additional binding to a Command and defining its CanExecute method.
In conclusion, please, check out the referenced resources and let me know if they help.
Best regards,Bozhidara PachilovaSoftware Developer
Your solution is great!, the code worked and is very simple for me to use it. however I encounter a small issue: the XamDataGrid is not refreshing. It refreshes the content of the changed field, but the visibility of the textblocks withing the template field stays the same. My datasource is a hierarchical and only when I collapse the child and expand it again the visibility is refreshed, any thoughts?