Listview模板与链接

时间:2014-04-14 13:21:09

标签: c# wpf listview

我有一个列表视图:

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

我想在单击要打开的文件的文件名(仅文件名,而不是日期)时(或任何自定义操作),即文件名为链接的列。我怎么能这样做?

1 个答案:

答案 0 :(得分:2)

您可以在 DataTemplate

中使用超链接
  <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>