[英]C# WPF add Navigation Handler to DataGridHyperlinkColumn
I'm having a problem with a WPF C# .NEt 4.5 application. WPF C#.NEt 4.5应用程序出现问题。
I'm programmatically creating a DataGridHyperlinkColumn inside a Grid. 我正在以编程方式在Grid中创建DataGridHyperlinkColumn。
Meaning that almost nothing is written in the xaml file but created directly by the .cs 这意味着几乎没有任何内容写入xaml文件中,而是由.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. 使用此代码,我可以用链接填充网格,单击该链接将激活我的
hyperlink_Click
_点击功能。
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. 但是现在我无法将
new RequestNavigateEventHandler(hyperlink_Click)
附加到将填充网格的每个链接。
At the current time my grid is populate with links, that are not possibile to be clicked. 目前,我的网格中充满了无法单击的链接。
Thanks for any suggestions! 感谢您的任何建议!
This would be the equivalent of your XAML: 这相当于您的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
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.