0
我有一個gridview,我需要使我的鏈接列可點擊和捕捉點擊事件。如何使gridview列超鏈接可點擊並捕獲事件?
在超鏈接列中,我添加了這個RequestNavigate =「Hyperlink_RequestNavigate」,但當點擊url鏈接時它不起作用。
請給我一個提醒
這裏是我的代碼
<Grid>
<ListView Margin="10,52,12,61" Name="ListView1">
<ListView.View>
<GridView AllowsColumnReorder="true" ColumnHeaderToolTip="Authors" ColumnHeaderTemplate="{StaticResource OrangeHeaderTemplate}" >
<!-- Add a ContextMenu to GridView Header -->
<GridView.ColumnHeaderContextMenu>
<ContextMenu >
<MenuItem Header="Ascending" Click="MenuItem_Click" />
<MenuItem Header="Descending" />
</ContextMenu>
</GridView.ColumnHeaderContextMenu>
<!-- Add GridView Columns -->
<GridViewColumn Header=" Link" Width="120" DisplayMemberBinding="{Binding Path=Url}" >
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock>
<Hyperlink NavigateUri="{Binding Path=URL}" RequestNavigate="Hyperlink_RequestNavigate">
</Hyperlink>
</TextBlock>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header=" Name" Width="120" DisplayMemberBinding="{Binding Path=Name}" />
<GridViewColumn Header=" Age" Width="50" DisplayMemberBinding="{Binding Path=Age}" />
<GridViewColumn Header=" Book" Width="250" DisplayMemberBinding="{Binding Path=Book}" />
<GridViewColumn Header=" MVP" Width="50" DisplayMemberBinding="{Binding Path=MVP}" ></GridViewColumn>
</GridView>
</ListView.View>
</ListView>
</Grid>
C#代碼
private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e)
{
Process.Start(new ProcessStartInfo(e.Uri.AbsoluteUri));
e.Handled = true;
}
//
private void CreateDynamicGridView()
{
// Create a GridView
GridView grdView = new GridView();
grdView.AllowsColumnReorder = true;
grdView.ColumnHeaderToolTip = "Authors";
GridViewColumn nameColumn = new GridViewColumn();
nameColumn.DisplayMemberBinding = new Binding("Name");
nameColumn.Header = "Author Name";
nameColumn.Width = 120;
grdView.Columns.Add(nameColumn);
GridViewColumn ageColumn = new GridViewColumn();
ageColumn.DisplayMemberBinding = new Binding("Age");
ageColumn.Header = "Age";
ageColumn.Width = 30;
grdView.Columns.Add(ageColumn);
GridViewColumn bookColumn = new GridViewColumn();
bookColumn.DisplayMemberBinding = new Binding("Book");
bookColumn.Header = "Book";
bookColumn.Width = 250;
grdView.Columns.Add(bookColumn);
GridViewColumn mvpColumn = new GridViewColumn();
mvpColumn.DisplayMemberBinding = new Binding("Mvp");
mvpColumn.Header = "Mvp";
mvpColumn.Width = 50;
grdView.Columns.Add(mvpColumn);
ListView1.View = grdView;
}
private ArrayList AuthorsList()
{
ArrayList list = new ArrayList();
list.Add(new Author("http://google.com", "Mahesh Chand", 30, "ADO.NET Programming", true));
list.Add(new Author("http://facebook.com", "Mike Gold", 35, "Programming C#", true));
list.Add(new Author("http://google.com", "Raj Kumar", 25, "WPF Cookbook", false));
list.Add(new Author("http://ok.ru", "Tony Parker", 48, "VB.NET Coding", false));
list.Add(new Author("http://mail.ru", "Renee Ward", 22, "Coding Standards", true));
list.Add(new Author("http://ya.ru", "Praveen Kumar", 33, "Vista Development", false));
return list;
}
private void MenuItem_Click(object sender, RoutedEventArgs e)
{
}
}
public class Author
{
public Author(string url, string authorName, Int16 authorAge, string authorBook, bool authorMVP)
{
this.Url = url;
this.Name = authorName;
this.Age = authorAge;
this.Book = authorBook;
this.Mvp = authorMVP;
}
private string _url;
public string Url
{
get { return _url; }
set { _url = value; }
}
private string name;
public string Name
{
get { return name; }
set { name = value; }
}
private Int16 age;
public Int16 Age
{
get { return age; }
set { age = value; }
}
private string book;
public string Book
{
get { return book; }
set { book = value; }
}
private bool mvp;
public bool Mvp
{
get { return mvp; }
set { mvp = value; }
}
}
什麼.NET框架? – CurseStacker 2015-03-02 09:50:51
3.5框架,但我也可以使用4或4.5 – Garnik 2015-03-02 09:53:58
對不起,但這是一個ASP.NET Web窗體? – CurseStacker 2015-03-02 10:03:08