3

I am using the following code to create hyperlink column in xceed grid in wpf. When am binding a datatable to xceed grid, the value is binding but the hyperlink is not created. Please help me.

<DataTemplate x:Key="ButtonTemplate">
        <TextBlock>
        <Hyperlink Click="Hyperlink_Click">
            <StackPanel Orientation="Horizontal">
            <TextBlock Text="{Binding Path=.}"/>
         <TextBlock Text="{Binding RelativeSource={RelativeSource   
             AncestorType= {x:Type xcdg:DataRow}},Path=DataContext.[Documents]}"/>
                </StackPanel>
        </Hyperlink>
    </TextBlock>
    </DataTemplate>
Nerd in Training
  • 2,098
  • 1
  • 22
  • 44
Mathan
  • 61
  • 2
  • 3

1 Answers1

3
<xcdg:Column FieldName="ColumnTest" Title="Test">
                    <xcdg:Column.CellContentTemplate>
                        <DataTemplate>
                            <TextBlock>
                                <Hyperlink RequestNavigate="Hyperlink_RequestNavigate" NavigateUri="{Binding .}">
                                    <TextBlock Text="{Binding .}" />
                                </Hyperlink>
                            </TextBlock>
                        </DataTemplate>

                    </xcdg:Column.CellContentTemplate>
                </xcdg:Column>

You will need to add the RequestNavigate event handler so that when the hyperlink is clicked, you can send the request. This should open up your default browser and go straight to your page.

here is the code for the event handler:

private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e)
        {
            Process.Start(new ProcessStartInfo(e.Uri.AbsoluteUri));

            e.Handled = true;
        }
Nerd in Training
  • 2,098
  • 1
  • 22
  • 44
  • Credit to Syed Shoaib Abidi in (https://stackoverflow.com/questions/22881865/hyperlinks-in-wpf-browser-not-working) If you are dynamically creating the hyperlink in the code behind here's the logic: (where h is the name of the hyperlink object): h.RequestNavigate += (sender, e) => { System.Diagnostics.Process.Start(e.Uri.ToString()); }; – Jeff Mar 30 '22 at 03:42