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.










share|improve this question
























  • 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















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.










share|improve this question
























  • 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













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.










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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


















  • 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












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






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    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

























    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






    share|improve this answer

























      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






      share|improve this answer























        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






        share|improve this answer












        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







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 19 at 7:21









        MarHazK

        1




        1






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Costa Masnaga

            Fotorealismo

            Sidney Franklin