I have a XamDataGrid in which there is a Column COUNT to which the values are assigned dynamically.
What i want is if the column cell value is 2 then convert it to hyperlink with text CLICK and if the cell value is 1 then it should remain as it is(no hyperlink, no text change).
Kind Regards
Hello Bozhidara Pachilova
That worked. Thanks!
Hi Sachin,
I am glad that you find my suggestion helpful!
To address your new query, with this requirement included, I would suggest adopting a slightly different approach given the fact that the choice would be between at least three different templates and that a simple equality check for the field’s value would not suffice to determine whether the string contains the ‘~’ character in the Style’s triggers.
So, I believe you will find the Apply Cell Value Templates Conditionally topic in our documentation very helpful on the matter. This approach involves declaring your field as a TemplateField and setting a “selector” that would provide conditional logic for applying different templates based on the field value. The selector class should extend from the DataTemplateSelector class and implement the SelectTemplate method which returns a DataTemplate type.
I have modified the previous sample to demonstrate this suggestion. In the XamDataGrid’s Resources collection is included the custom template selector “MyDisplayTemplateSelector” as well as three different data templates, for the three separate cases – when the value is “2”, “1” and when there is the “Special” case. As you will see, the templates leverage the custom TemplateEditorValueBinding markup extension for binding to the ValueEditor.Value property of a TemplateEditor. A slightly more complicated binding is also introduced to bind to the template editor’s DataContext in order to access the “Hyperlink” property on the DataItem. Finally, the custom selector is assigned as the TemplateField’s DisplayTemplateSelector. As you will read in the referenced topic, the DisplayTemplate provides a template for cells that are not in edit mode for a specific TemplateField. Should an EditTemplate be provided in a similar way, the EditTemplateSelector has to be provided.
In conclusion, please check out these resources and let me know if I may be of any further assistance on the matter.
Best regards,Bozhidara PachilovaAssociate Software Developer
0333.XDGConditionalHyperlink2.zip
Hello Bozhidara Pachilova,
Thank you for helping me out with your sample.
I have another query related to my project, how can i make my cell value to hyperlink and change its text to SPECIAL if my cell value have any special symbol(~) in it.
Ex-:
COUNT ="Test~Case~1"
if count contains symbol(~) ,Cell should look like SPECIAL with hyperlink on it.
Thank you for posting to Infragistics Community!
I have been looking into your question and created a small sample with a XamDataGrid to demonstrate how your requirement can be achieved. You can find it attached below.
The approach involves declaring a keyed style, targeting the CellValuePresenter type and assigning it as the CellValuePresenterStyle property of your target column. The style would introduce DataTrigger for the corresponding values and bound to the target DataItem’s propery. Then, for any value, the Template property could be set to a custom ControlTemplate, for example such that it contains a hyperlink.
Here is a snippet of the sample grid’s markup:
<igWPF:XamDataGrid DataSource="{Binding Data}" Height="400"> <igWPF:XamDataGrid.Resources> <Style x:Key="HyperlinkStyle" TargetType="Hyperlink"> <EventSetter Event="RequestNavigate" Handler="Hyperlink_RequestNavigate"></EventSetter> </Style> <Style TargetType="{x:Type igWPF:CellValuePresenter}" x:Key="CoalCVPStyle"> <Style.Triggers> <DataTrigger Binding="{Binding Path=DataItem.Coal}" Value="1"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type igWPF:CellValuePresenter}"> <TextBlock> <Hyperlink NavigateUri="{Binding Path=DataItem.Hyperlink}" Style="{StaticResource HyperlinkStyle}"> <Run Text="{Binding Path=DataItem.Coal}" /> </Hyperlink> </TextBlock> </ControlTemplate> </Setter.Value> </Setter> </DataTrigger> <DataTrigger Binding="{Binding Path=DataItem.Coal}" Value="2"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type igWPF:CellValuePresenter}"> <TextBlock Text="{Binding Path=DataItem.Coal}"></TextBlock> </ControlTemplate> </Setter.Value> </Setter> </DataTrigger> </Style.Triggers> </Style> </igWPF:XamDataGrid.Resources> <igWPF:XamDataGrid.FieldLayoutSettings> <igWPF:FieldLayoutSettings AutoGenerateFields="False" /> </igWPF:XamDataGrid.FieldLayoutSettings> <igWPF:XamDataGrid.FieldLayouts> <igWPF:FieldLayout> <igWPF:FieldLayout.Fields> <igWPF:Field Name="Country" /> <igWPF:TextField Name="Region" /> <igWPF:TextField Name="Coal" CellValuePresenterStyle="{StaticResource CoalCVPStyle}"/> </igWPF:FieldLayout.Fields> </igWPF:FieldLayout> </igWPF:XamDataGrid.FieldLayouts> </igWPF:XamDataGrid>
I hope this helps achieve your requirement. Please, test this on your side and let me know of any other questions on the matter.
2843.XDGConditionalHyperlink.zip