Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
110
How To Create Dynamic Hyperlink Based On Specific Cell Value?
posted

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

Parents
No Data
Reply
  • 2680
    Verified Answer
    Offline posted

    Hi Sachin,

    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.

    Best regards,
    Bozhidara Pachilova
    Associate Software Developer

    2843.XDGConditionalHyperlink.zip

Children