How to add dynamically created hyperlink to stack panel programmatically wpf
up vote
-2
down vote
favorite
i am creating hyperlinks and want to add it to stack panel.
for (int i = 1; i <= links.Length; i++)
{
Hyperlink hyperlink = new Hyperlink()
{
NavigateUri = new Uri(links[i - 1])
};
}
hyperlink.RequestNavigate += new System.Windows.Navigation.RequestNavigateEventHandler(this.Hyperlink_RequestNavigate);
mainControl.Children.Add(hyperlink);
it gives me error -
cannot convert to system.windows.documents.hyperlink to system.windows.uielement.
i understand the namespace error but didn't find resolution because in uielement i dint find hyperlink.
c# .net wpf
add a comment |
up vote
-2
down vote
favorite
i am creating hyperlinks and want to add it to stack panel.
for (int i = 1; i <= links.Length; i++)
{
Hyperlink hyperlink = new Hyperlink()
{
NavigateUri = new Uri(links[i - 1])
};
}
hyperlink.RequestNavigate += new System.Windows.Navigation.RequestNavigateEventHandler(this.Hyperlink_RequestNavigate);
mainControl.Children.Add(hyperlink);
it gives me error -
cannot convert to system.windows.documents.hyperlink to system.windows.uielement.
i understand the namespace error but didn't find resolution because in uielement i dint find hyperlink.
c# .net wpf
is this winforms or wpf?
– JohnB
Nov 19 at 7:18
this application is in wpf
– sum1
Nov 19 at 7:20
then why in the wide-world-of-sports did you tag winforms?
– JohnB
Nov 19 at 7:21
add a comment |
up vote
-2
down vote
favorite
up vote
-2
down vote
favorite
i am creating hyperlinks and want to add it to stack panel.
for (int i = 1; i <= links.Length; i++)
{
Hyperlink hyperlink = new Hyperlink()
{
NavigateUri = new Uri(links[i - 1])
};
}
hyperlink.RequestNavigate += new System.Windows.Navigation.RequestNavigateEventHandler(this.Hyperlink_RequestNavigate);
mainControl.Children.Add(hyperlink);
it gives me error -
cannot convert to system.windows.documents.hyperlink to system.windows.uielement.
i understand the namespace error but didn't find resolution because in uielement i dint find hyperlink.
c# .net wpf
i am creating hyperlinks and want to add it to stack panel.
for (int i = 1; i <= links.Length; i++)
{
Hyperlink hyperlink = new Hyperlink()
{
NavigateUri = new Uri(links[i - 1])
};
}
hyperlink.RequestNavigate += new System.Windows.Navigation.RequestNavigateEventHandler(this.Hyperlink_RequestNavigate);
mainControl.Children.Add(hyperlink);
it gives me error -
cannot convert to system.windows.documents.hyperlink to system.windows.uielement.
i understand the namespace error but didn't find resolution because in uielement i dint find hyperlink.
c# .net wpf
c# .net wpf
edited Nov 19 at 15:26
James Z
11.1k71735
11.1k71735
asked Nov 19 at 7:15
sum1
111
111
is this winforms or wpf?
– JohnB
Nov 19 at 7:18
this application is in wpf
– sum1
Nov 19 at 7:20
then why in the wide-world-of-sports did you tag winforms?
– JohnB
Nov 19 at 7:21
add a comment |
is this winforms or wpf?
– JohnB
Nov 19 at 7:18
this application is in wpf
– sum1
Nov 19 at 7:20
then why in the wide-world-of-sports did you tag winforms?
– JohnB
Nov 19 at 7:21
is this winforms or wpf?
– JohnB
Nov 19 at 7:18
is this winforms or wpf?
– JohnB
Nov 19 at 7:18
this application is in wpf
– sum1
Nov 19 at 7:20
this application is in wpf
– sum1
Nov 19 at 7:20
then why in the wide-world-of-sports did you tag winforms?
– JohnB
Nov 19 at 7:21
then why in the wide-world-of-sports did you tag winforms?
– JohnB
Nov 19 at 7:21
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
Use LinkLabel instead of HyperLink
Samples:
using System;
using System.Drawing;
using System.Windows.Forms;
public class LinkLabelAddLink : Form {
LinkLabel lnkLA = new LinkLabel();
public LinkLabelAddLink(){
Size = new Size(300,250);
lnkLA.Parent = this;
lnkLA.Text = "StackOverflow.com";
lnkLA.Location = new Point(0,25);
lnkLA.AutoSize = true;
lnkLA.BorderStyle = BorderStyle.None;
lnkLA.Links.Add(0,7,"www.stackoverflow.com");
lnkLA.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(lnkLA_LinkClicked);
}
static void Main()
{
Application.Run(new LinkLabelAddLink());
}
private void lnkLA_LinkClicked(object sender,LinkLabelLinkClickedEventArgs e)
{
lnkLA.LinkVisited = true;
System.Diagnostics.Process.Start(e.Link.LinkData.ToString());
}
}
PS: You need atleast .NET 4.5
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
Use LinkLabel instead of HyperLink
Samples:
using System;
using System.Drawing;
using System.Windows.Forms;
public class LinkLabelAddLink : Form {
LinkLabel lnkLA = new LinkLabel();
public LinkLabelAddLink(){
Size = new Size(300,250);
lnkLA.Parent = this;
lnkLA.Text = "StackOverflow.com";
lnkLA.Location = new Point(0,25);
lnkLA.AutoSize = true;
lnkLA.BorderStyle = BorderStyle.None;
lnkLA.Links.Add(0,7,"www.stackoverflow.com");
lnkLA.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(lnkLA_LinkClicked);
}
static void Main()
{
Application.Run(new LinkLabelAddLink());
}
private void lnkLA_LinkClicked(object sender,LinkLabelLinkClickedEventArgs e)
{
lnkLA.LinkVisited = true;
System.Diagnostics.Process.Start(e.Link.LinkData.ToString());
}
}
PS: You need atleast .NET 4.5
add a comment |
up vote
0
down vote
Use LinkLabel instead of HyperLink
Samples:
using System;
using System.Drawing;
using System.Windows.Forms;
public class LinkLabelAddLink : Form {
LinkLabel lnkLA = new LinkLabel();
public LinkLabelAddLink(){
Size = new Size(300,250);
lnkLA.Parent = this;
lnkLA.Text = "StackOverflow.com";
lnkLA.Location = new Point(0,25);
lnkLA.AutoSize = true;
lnkLA.BorderStyle = BorderStyle.None;
lnkLA.Links.Add(0,7,"www.stackoverflow.com");
lnkLA.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(lnkLA_LinkClicked);
}
static void Main()
{
Application.Run(new LinkLabelAddLink());
}
private void lnkLA_LinkClicked(object sender,LinkLabelLinkClickedEventArgs e)
{
lnkLA.LinkVisited = true;
System.Diagnostics.Process.Start(e.Link.LinkData.ToString());
}
}
PS: You need atleast .NET 4.5
add a comment |
up vote
0
down vote
up vote
0
down vote
Use LinkLabel instead of HyperLink
Samples:
using System;
using System.Drawing;
using System.Windows.Forms;
public class LinkLabelAddLink : Form {
LinkLabel lnkLA = new LinkLabel();
public LinkLabelAddLink(){
Size = new Size(300,250);
lnkLA.Parent = this;
lnkLA.Text = "StackOverflow.com";
lnkLA.Location = new Point(0,25);
lnkLA.AutoSize = true;
lnkLA.BorderStyle = BorderStyle.None;
lnkLA.Links.Add(0,7,"www.stackoverflow.com");
lnkLA.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(lnkLA_LinkClicked);
}
static void Main()
{
Application.Run(new LinkLabelAddLink());
}
private void lnkLA_LinkClicked(object sender,LinkLabelLinkClickedEventArgs e)
{
lnkLA.LinkVisited = true;
System.Diagnostics.Process.Start(e.Link.LinkData.ToString());
}
}
PS: You need atleast .NET 4.5
Use LinkLabel instead of HyperLink
Samples:
using System;
using System.Drawing;
using System.Windows.Forms;
public class LinkLabelAddLink : Form {
LinkLabel lnkLA = new LinkLabel();
public LinkLabelAddLink(){
Size = new Size(300,250);
lnkLA.Parent = this;
lnkLA.Text = "StackOverflow.com";
lnkLA.Location = new Point(0,25);
lnkLA.AutoSize = true;
lnkLA.BorderStyle = BorderStyle.None;
lnkLA.Links.Add(0,7,"www.stackoverflow.com");
lnkLA.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(lnkLA_LinkClicked);
}
static void Main()
{
Application.Run(new LinkLabelAddLink());
}
private void lnkLA_LinkClicked(object sender,LinkLabelLinkClickedEventArgs e)
{
lnkLA.LinkVisited = true;
System.Diagnostics.Process.Start(e.Link.LinkData.ToString());
}
}
PS: You need atleast .NET 4.5
answered Nov 19 at 7:21
MarHazK
1
1
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53369894%2fhow-to-add-dynamically-created-hyperlink-to-stack-panel-programmatically-wpf%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
is this winforms or wpf?
– JohnB
Nov 19 at 7:18
this application is in wpf
– sum1
Nov 19 at 7:20
then why in the wide-world-of-sports did you tag winforms?
– JohnB
Nov 19 at 7:21