M
M
Michael2015-04-11 21:22:34
WPF
Michael, 2015-04-11 21:22:34

How to set Hyperlink property NavigateUri in XAML from resources?

I'm trying to set the Hyperlink property to NavigateUri like this:

<Hyperlink NavigateUri="{x:Static res:Resources.MyLink}" 
                  RequestNavigate="Hyperlink_RequestNavigate" >
         <Run Text="{x:Static res:Resources.MyLinkName}" />
 </Hyperlink>

But during execution, the application crashes:
System.Windows.Markup.XamlParseException occurred
HResult=-2146233087
Message="Setting the property 'System.Windows.Documents.Hyperlink.NavigateUri' threw an exception.": line number "94" and line position "14".
Source=PresentationFramework

If you just write a link in XAML, then everything works. I suppose that you can set the link in C # code, but I'm interested in the way with setting the link directly in XAML. In resources, the usual line of the formhttp://www.apache.org/

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Michael, 2015-04-11
@gmikhail94

I asked the question myself, and I will answer it myself. This is how it works:

<Hyperlink NavigateUri="{Binding Source={x:Static res:Resources.MyLink}}" 
                  RequestNavigate="Hyperlink_RequestNavigate" >
         <Run Text="{x:Static res:Resources.MyLinkName}" />
 </Hyperlink>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question