0

A window loads some dynamic Xaml which gets transformed with Xslt to display some content from a data source. Because the Xaml is dynamic, I cannot bind events until after it's loaded - the binding itself is okay, but I'm struggling to find a way to describe the event data in the source Xaml.

Let's say my source is as follows:

<Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
   <xsl:variable name="myValue" select="/root/System/CustomerFirstName"/>
   <Label ##MyClick="method='myMethod', aParameter='$myValue', anotherParameter='test'"##>
      <xsl:value-of select="/root/System/CustomerFirstName" />
   </Label>
</Grid>

The code puts it through the Xslt processor which works perfectly if the bit between the ## is removed. I understand why it doesn't like the MyClick attribute as it's not defined. I have tried adding an attached property but the Xslt parser doesn't seem to know about it (maybe I'm missing a hookup). I've tried adding an extension object but the Xslt parser wants to call the method as it parses, instead of me handling that bit when a user clicks on the UI element.

What I want is the Xslt parser to preprocess but leave in my custom tag, such that any content is processed:

<Label MyClick="method='myMethod', aParameter='Geoff', anotherParameter='test'"> [etc]

The actual syntax of the inner text of MyClick is not important, as long as once the Xslt completes, I can walk the generated Xaml to find any nodes with MyClick defined and do my own processing on the content - in this case binding a Click event handler and then doing something with the parameters passed.

Another way, perhaps, is instead of attributes defining my custom behaviour, it is instead subelements inside the Label element. I can work with either, such as:

<Label><MyClick><Method>wibble</Method><Parameter Name="name" Value="{$myValue}"></Parameter></MyClick></Label>

...kind of thing

Ideas much appreciated.

GeoffM
  • 1,603
  • 5
  • 22
  • 34
  • 1
    Which XSLT processor do you use, how do you run it, which error exactly do you get from the XSLT processor? A literal result element in the form `` is not in any way something an XSLT processor would fail with, it doesn't need to have a definition of any result element or attribute. – Martin Honnen Jan 25 '20 at 12:44
  • You're right... it was the XamlReader, not the XslCompiledTransform throwing the exception. Thank you. Next time I need to read more carefully. – GeoffM Jan 25 '20 at 15:19

0 Answers0