Mathan
Mathan

Reputation: 61

Hyperlink in wpf

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>

Upvotes: 3

Views: 2959

Answers (1)

Nerd in Training
Nerd in Training

Reputation: 2220

<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;
        }

Upvotes: 3

Related Questions