.net - Start a process from a bound wpf hyperlink -


what's simple way have wpf hyperlink run process.start on (data-bound) text content?

one way (that improved refactoring usercontrol or static class or valueconverter or ...) have hyperlink bound command on viewmodel , pass in content of hyperlink (i couldn't find way relative binding) command parameter.

wpf snippet

<textblock>     <textblock.datacontext>         <viewmodels:viewmodel />     </textblock.datacontext>     <hyperlink command="{binding launchhyperlinkcommand}" commandparameter="{binding elementname=_content, path=text}">     <run text="{binding filepath, mode=oneway}" name="_content"/>     </hyperlink> </textblock> 

c# datacontext class snippet (note: using prism)

public class viewmodel : notificationobject {     public string filepath { get; private set; }      public delegatecommand<string> launchhyperlinkcommand { get; set; }      public viewmodel()     {         launchhyperlinkcommand = new delegatecommand<string>(launchhyperlink);     }      private static void launchhyperlink(string link)     {         try         {             process.start(link);         }         catch (exception e)         {             messagebox.show(e.message);         }     } } 

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -