1

I'm having a problem with a WPF C# .NEt 4.5 application.

I'm programmatically creating a DataGridHyperlinkColumn inside a Grid.

Meaning that almost nothing is written in the xaml file but created directly by the .cs

What I'm trying to achieve is the following:

<DataGridHyperlinkColumn Header="Path" Binding="{Binding Path=FullPath}" ContentBinding="{Binding Path=Name}" IsReadOnly="True" Width="*">
   <DataGridHyperlinkColumn.ElementStyle>
      <Style>
         <EventSetter Event="Hyperlink.Click" Handler="hyperlink_Click"/>
      </Style>
   </DataGridHyperlinkColumn.ElementStyle>
</DataGridHyperlinkColumn>

With this code I'm able to populate my Grid with links, which when clicked will activate my hyperlink_Click function.

Now if I'll do this by code the result is the following:

        DataGridHyperlinkColumn parent = new DataGridHyperlinkColumn
        {
            Binding = new Binding("ParentName"),
        };

But now I'm not able to attach a new RequestNavigateEventHandler(hyperlink_Click) to each link which will populate my Grid.

At the current time my grid is populate with links, that are not possibile to be clicked.

Thanks for any suggestions!

1 Answer 1

2

This would be the equivalent of your XAML:

Style style = new Style();
style.Setters.Add(new EventSetter(Hyperlink.ClickEvent, new RoutedEventHandler(hyperlink_Click)));
DataGridHyperlinkColumn parent = new DataGridHyperlinkColumn
{
    Header = "Path",
    Binding = new Binding("FullPath"),
    ContentBinding = new Binding("Name"),
    IsReadOnly = true,
    ElementStyle = style
};
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.