如何使数据网格中某些列的内容成为超链接?
我想知道这是否是一件容易的事。我需要将数据网格内的一些文本作为超链接。我使用 XMLDataProvider 生成内容。任何想法都受到高度赞赏。
我的数据网格如下所示。我正在使用 WPF 工具包:
<DataGrid x:Name="MainGrid" GridLinesVisibility="Horizontal" AutoGenerateColumns="False" RowHeight="20" ItemsSource="{Binding XPath=/ServicesTiles/Servers}"
HeadersVisibility="None" Margin="10,15,0,0"
HorizontalGridLinesBrush="{x:Null}"
BorderBrush="{x:Null}"
VerticalGridLinesBrush="{x:Null}"
Background="{x:Null}"
RowBackground="{x:Null}"
CellStyle="{DynamicResource DataGridCellStyle1}"
HorizontalAlignment="Left">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding XPath=@Name}" Foreground="#FF6E6E6E" MinWidth="160" />
<DataGridTextColumn Binding="{Binding XPath=@Status}" Foreground="#FF6E6E6E" MinWidth="270"/>
<DataGridTextColumn Binding="{Binding XPath=@Name2}" Foreground="#FF6E6E6E" MinWidth="220"/>
<DataGridTextColumn Binding="{Binding XPath=@Status2}" Foreground="#FF6E6E6E" MinWidth="220"/>
</DataGrid.Columns>
</DataGrid>
I am wondering if it is an easy task. I need to have some of the text inside the datagrid to be hyperlinks. I generated content with XMLDataProvider. Any ideas are highly appreciated.
My DataGrid looks below. I am working with WPF toolkit:
<DataGrid x:Name="MainGrid" GridLinesVisibility="Horizontal" AutoGenerateColumns="False" RowHeight="20" ItemsSource="{Binding XPath=/ServicesTiles/Servers}"
HeadersVisibility="None" Margin="10,15,0,0"
HorizontalGridLinesBrush="{x:Null}"
BorderBrush="{x:Null}"
VerticalGridLinesBrush="{x:Null}"
Background="{x:Null}"
RowBackground="{x:Null}"
CellStyle="{DynamicResource DataGridCellStyle1}"
HorizontalAlignment="Left">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding XPath=@Name}" Foreground="#FF6E6E6E" MinWidth="160" />
<DataGridTextColumn Binding="{Binding XPath=@Status}" Foreground="#FF6E6E6E" MinWidth="270"/>
<DataGridTextColumn Binding="{Binding XPath=@Name2}" Foreground="#FF6E6E6E" MinWidth="220"/>
<DataGridTextColumn Binding="{Binding XPath=@Status2}" Foreground="#FF6E6E6E" MinWidth="220"/>
</DataGrid.Columns>
</DataGrid>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
下面的DataGridColumn应该做你想做的事(我没有测试过,如果不起作用,请发表评论)
编辑
根据要求,这里是我的建议如何插入。让我知道它是否有效...
The following DataGridColumn should do what you want (I have not tested, make a comment, if it does not work)
Edit
as requested, here my proposition how to insert. Let me know if it works...
使用
超链接
上的命令
。如果您想回调到DataGrid
的DataContext
,您将需要使用FindAncestor
并搜索类型DataGrid< /代码>。
Make use of the
Command
on theHyperlink
. If you want to call back into theDataContext
of theDataGrid
you will need to make use ofFindAncestor
and search for typeDataGrid
.