带有链接的列表视图模板
本文关键字:视图 列表 链接 | 更新日期: 2023-09-27 17:58:10
我有一个列表视图:
<ListView
VerticalAlignment="Top"
Width="210"
Height="150"
SelectedValuePath="SelectedFile"
SelectionMode="Single"
SelectedIndex="0"
behaviour:CommandsBehaviour.SelectionChanged = "{Binding SelectionFileChange}"
ItemsSource="{Binding files}"
IsSynchronizedWithCurrentItem="True"
atachedProperties:GridViewSort.AutoSort="True"
atachedProperties:GridViewSort.ShowSortGlyph="True">
<ListView.View>
<GridView>
<GridView.Columns>
<GridViewColumn Header="File Name" Width="100" DisplayMemberBinding="{Binding Name}"/>
<GridViewColumn Header="Date" Width="100" DisplayMemberBinding="{Binding Date}"/>
</GridView.Columns>
</GridView>
</ListView.View>
</ListView>
当我单击文件名(只有文件名,而不是日期)时,我希望打开该文件(或任何自定义操作),即带有文件名的列像链接一样。我该怎么做?
您可以在DataTemplate内使用Hyperlink
<ListView VerticalAlignment="Top" Width="210" Height="150" SelectedValuePath="SelectedFile"
SelectionMode="Single" SelectedIndex="0" ItemsSource="{Binding files}" >
<ListView.View>
<GridView>
<GridView.Columns>
<GridViewColumn Width="Auto" Header="URL" >
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Name="Name" MinWidth="100" Width="Auto">
<Hyperlink NavigateUri="{Binding Path=Name}" Name="NameURl" RequestNavigate="OpenPageRequestNavigate">
<TextBlock Text="{Binding Path=Name}"/>
</Hyperlink>
</TextBlock>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView.Columns>
</GridView>
</ListView.View>
</ListView>