Mario Stoilov
Mario Stoilov

Reputation: 3447

Listview template with link

I have a 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>

I want when I click the file name (only the file name, not the date) that file to be opened (or any custom action for that matter), i.e the column with the filename to be like a link. How can I do this?

Upvotes: 0

Views: 510

Answers (1)

Sajeetharan
Sajeetharan

Reputation: 222682

You can use Hyperlink inside 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>

Upvotes: 2

Related Questions