Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using custom XML namespaces to reference external DLLs in Kaxaml

I can get Kaxaml to load external assemblies using CLR-namespaces, that however is a pain because one needs a lot of mappings to target all the different namespaces in an assembly while the custom XmlnsDefinition on the assembly would allow one to get away with just one or a few.

When looking for a solution i obviously found this question but it only seems to cover the use of CLR-namespaces as none of the answers seemed to work for custom namespaces ("Cannot set unknown member ...").

Example:

<Page
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
  xmlns:is="http://schemas.microsoft.com/expression/2010/interactions">
<!-- ... -->
<Button Content="Test">
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="Click">
            <is:ChangePropertyAction PropertyName="IsOpen"
                                TargetName="popup"
                                Value="True" />
        </i:EventTrigger>
    </i:Interaction.Triggers>
</Button>

This will not work, however if you use CLRs it does:

<Page
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
  xmlns:is="clr-namespace:Microsoft.Expression.Interactions;assembly=Microsoft.Expression.Interactions"
  xmlns:isc="clr-namespace:Microsoft.Expression.Interactivity.Core;assembly=Microsoft.Expression.Interactions">
<!-- ... -->
<Button Content="Test">
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="Click">
            <isc:ChangePropertyAction PropertyName="IsOpen"
                                TargetName="popup"
                                Value="True" />
        </i:EventTrigger>
    </i:Interaction.Triggers>
</Button>

The is namespace is not used here and i had to add a sub-namespace of the interactions assembly.

It would be ideal if the first method could be made to work.

like image 724
H.B. Avatar asked Nov 20 '11 03:11

H.B.


1 Answers

So while typing this question i stumbled upon one way to use the custom namespaces: You have to make Kaxaml load the assembly at least once.

This can be done using some dummy object which references a CLR-namespace within the referenced assembly. If parsed once this loader can be discarded, of course this needs to be done every time Kaxaml is run. e.g.

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
        xmlns:is="http://schemas.microsoft.com/expression/2010/interactions">
    <Page.Resources>
        <FrameworkElement x:Key="loader"
                xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
                xmlns:is="clr-namespace:Microsoft.Expression.Interactions;assembly=Microsoft.Expression.Interactions" />
    </Page.Resources>

Using snippets or the default file this can be made comparatively convenient while still not ideal so if someone knows a good fix please let me know.

like image 123
H.B. Avatar answered Oct 07 '22 05:10

H.B.