PDA

Click to See Complete Forum and Search --> : Loading Hyperlink from XAML!


Mathiaslylo
Feb 21st, 2010, 03:41 PM
Hi there.

I'm using .NET Framework 4.0's System.XAML namespace to load an object from XAML code parsed as a string.

However, if I wish to load the code here:

<TextBlock><Hyperlink NavigateUri="http://test.com">Blah</Hyperlink></TextBlock>

Then how would I make the Hyperlink work? So far if I click it, nothing happens.

Mathiaslylo
Feb 25th, 2010, 02:58 PM
I still need help with this.

sciguyryan
Feb 25th, 2010, 03:23 PM
Add a click event with something like this:

private void MyHyperlink_Click(object sender, RoutedEventArgs e)
{
Process.Start(((Hyperlink)sender).NavigateUri.ToString());
}

Note: You will need to add a reference to System.Diagnostics.

Mathiaslylo
Feb 25th, 2010, 05:33 PM
Add a click event with something like this:

private void MyHyperlink_Click(object sender, RoutedEventArgs e)
{
Process.Start(((Hyperlink)sender).NavigateUri.ToString());
}

Note: You will need to add a reference to System.Diagnostics.

Doesn't work. You see, I am loading the link dynamically through the System.XAML namespace.

sciguyryan
Feb 25th, 2010, 05:34 PM
It shouldn't matter should it? You can dynamically add event handers after all.

Mathiaslylo
Feb 25th, 2010, 05:43 PM
I am getting this error:

System.Xaml.XamlObjectWriterException: 'Failed to create a 'Click' from the text 'LinkClicked'.' Line number '1' and line position '925'. ---> System.ArgumentException: Error binding to target method.

at System.Delegate.CreateDelegate(Type type, Object target, String method, Boolean ignoreCase, Boolean throwOnBindFailure)

at System.Xaml.Schema.SafeReflectionInvoker.CreateDelegate(Type delegateType, Object target, String methodName)

at System.Xaml.EventConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)

at MS.Internal.Xaml.Runtime.ClrObjectRuntime.CreateObjectWithTypeConverter(ServiceProviderContext serviceContext, XamlValueConverter`1 ts, Object value)

at MS.Internal.Xaml.Runtime.ClrObjectRuntime.CreateFromValue(ServiceProviderContext serviceContext, XamlValueConverter`1 ts, Object value, XamlMember property)

at System.Xaml.XamlObjectWriter.Logic_CreateFromValue(ObjectWriterContext ctx, XamlValueConverter`1 typeConverter, Object value, XamlMember property, String targetName, IAddLineInfo lineInfo)

--- End of inner exception stack trace ---

at System.Xaml.XamlObjectWriter.Logic_CreateFromValue(ObjectWriterContext ctx, XamlValueConverter`1 typeConverter, Object value, XamlMember property, String targetName, IAddLineInfo lineInfo)

at System.Xaml.XamlObjectWriter.Logic_CreatePropertyValueFromValue(ObjectWriterContext ctx)

at System.Xaml.XamlObjectWriter.WriteEndMember()

at System.Xaml.XamlWriter.WriteNode(XamlReader reader)

at System.Xaml.XamlServices.Transform(XamlReader xamlReader, XamlWriter xamlWriter, Boolean closeWriter)

at System.Xaml.XamlServices.Load(XamlReader xamlReader)

at System.Xaml.XamlServices.Parse(String xaml)

at TwitterClient.Flamefusion.XAML.XAMLUtility.LoadObjectFromXAML(String XAML) in C:\Users\Mathy\Documents\Visual Studio 2010\Projects\Flamefusion Standards\Flamefusion Standards\Standards.vb:line 1193

Mathiaslylo
Feb 25th, 2010, 05:44 PM
Oh, and the procedure handling it:

Public Sub LinkClicked(ByVal sender As Object, ByVal e As RoutedEventArgs)
MsgBox("Test")
End Sub